memo/completion/bash/memo.sh

50 lines
1.1 KiB
Bash
Raw Normal View History

2017-05-30 20:36:38 +02:00
#!/bin/bash
_memo(){
local cur opt prev
2017-06-02 00:10:06 +02:00
MEMO_FOLDER="${MEMO_DIR:-$HOME/memo}"
2018-08-09 23:32:34 +02:00
opts="add rm copy search show list"
2017-06-02 00:10:06 +02:00
2017-05-30 20:36:38 +02:00
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
case ${COMP_CWORD} in
1)
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}" ) )
return 0
;;
2)
prev="${COMP_WORDS[COMP_CWORD-1]}"
case ${prev} in
search)
return 1
;;
*)
2017-06-02 00:10:06 +02:00
entries=$( ls ${MEMO_FOLDER} )
2017-05-30 20:36:38 +02:00
COMPREPLY=( $(compgen -W "${entries}" -- "${cur}" ) )
return 0
;;
esac
;;
3)
operatior="${COMP_WORDS[COMP_CWORD-2]}"
case ${operatior} in
2017-06-02 00:10:06 +02:00
copy)
2017-05-30 20:36:38 +02:00
COMPREPLY=( $(compgen -f "${cur}" ) )
return 0
;;
*)
return 1
;;
esac
;;
*)
return 1
;;
esac
}
complete -F _memo memo