diff options
author | Karel Kočí <cynerd@email.cz> | 2016-10-12 22:18:55 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2016-10-12 22:31:03 +0200 |
commit | 5fb99b7dd7351a70c7c9963948cb29bdcfd86eb6 (patch) | |
tree | 25652986517c99f49648522ed551b67dd58e9cc7 /completions/bash | |
parent | 0b34fe0c09c78a954b7be230d2846172b40cdf40 (diff) | |
download | note-5fb99b7dd7351a70c7c9963948cb29bdcfd86eb6.tar.gz note-5fb99b7dd7351a70c7c9963948cb29bdcfd86eb6.tar.bz2 note-5fb99b7dd7351a70c7c9963948cb29bdcfd86eb6.zip |
Add bash completion
Diffstat (limited to 'completions/bash')
-rw-r--r-- | completions/bash | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/completions/bash b/completions/bash new file mode 100644 index 0000000..e733430 --- /dev/null +++ b/completions/bash @@ -0,0 +1,47 @@ +# Bash completion file for note +# vim: ft=sh + +_note_complete_notes() { + local IFS=$'\n' + local prefix="~/.notes/" + local items=($(compgen -f $prefix$cur)) + for item in ${items[@]}; do + # Ignore hidden files + [[ $item =~ /\.[^/]*$ ]] && continue + + # TODO if there is only single file in directory that match it + + # append / to directories + [ -d $item ] && item="$item/" + + COMPREPLY+=("${item#$prefix}") + done +} + +_note() { + local cur prev ops + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + + if [[ $COMP_CWORD -gt 1 ]]; then + case "${COMP_WORDS[1]}" in + delete|create|edit|less) + if [[ $COMP_CWORD -ge 2 ]]; then return; fi + _note_complete_notes + ;; + move) + if [[ $COMP_CWORD -ge 3 ]]; then return; fi + _note_complete_notes + ;; + git) + # TODO is there way to call git completition? + ;; + esac + else + local ops="delete create edit move less git" + COMPREPLY+=($(compgen -W "${ops}" -- ${cur})) + _note_complete_notes + fi +} + +complete -o filenames -o nospace -F _note note |