cheat/scripts/cheat.zsh

66 lines
1.7 KiB
Bash
Raw Normal View History

2020-04-03 07:01:25 +02:00
#compdef cheat
local cheats taglist pathlist
2020-04-03 07:01:25 +02:00
2020-04-12 04:03:08 +02:00
_cheat_complete_personal_cheatsheets()
2020-04-03 07:01:25 +02:00
{
cheats=("${(f)$(cheat -l -t personal | tail -n +2 | cut -d' ' -f1)}")
_describe -t cheats 'cheats' cheats
}
2020-04-12 04:03:08 +02:00
_cheat_complete_full_cheatsheets()
{
cheats=("${(f)$(cheat -l | tail -n +2 | cut -d' ' -f1)}")
_describe -t cheats 'cheats' cheats
}
2020-04-03 07:01:25 +02:00
_cheat_complete_tags()
{
taglist=("${(f)$(cheat -T)}")
_describe -t taglist 'taglist' taglist
}
_cheat_complete_paths()
{
pathlist=("${(f)$(cheat -d | cut -d':' -f1)}")
_describe -t pathlist 'pathlist' pathlist
}
_cheat() {
_arguments -C \
'(--init)--init[Write a default config file to stdout]: :->none' \
'(-c --colorize)'{-c,--colorize}'[Colorize output]: :->none' \
'(-d --directories)'{-d,--directories}'[List cheatsheet directories]: :->none' \
2020-04-12 04:03:08 +02:00
'(-e --edit)'{-e,--edit}'[Edit <sheet>]: :->personal' \
2020-04-03 07:01:25 +02:00
'(-l --list)'{-l,--list}'[List cheatsheets]: :->full' \
'(-p --path)'{-p,--path}'[Return only sheets found on path <name>]: :->pathlist' \
'(-r --regex)'{-r,--regex}'[Treat search <phrase> as a regex]: :->none' \
'(-s --search)'{-s,--search}'[Search cheatsheets for <phrase>]: :->none' \
'(-t --tag)'{-t,--tag}'[Return only sheets matching <tag>]: :->taglist' \
'(-T --tags)'{-T,--tags}'[List all tags in use]: :->none' \
'(-v --version)'{-v,--version}'[Print the version number]: :->none' \
2021-06-07 11:42:47 +02:00
'(--rm)--rm[Remove (delete) <sheet>]: :->personal'
2020-04-03 07:01:25 +02:00
case $state in
(none)
;;
(full)
2020-04-12 04:03:08 +02:00
_cheat_complete_full_cheatsheets
;;
(personal)
_cheat_complete_personal_cheatsheets
2020-04-03 07:01:25 +02:00
;;
(taglist)
_cheat_complete_tags
;;
(pathlist)
_cheat_complete_paths
;;
(*)
;;
esac
}
2024-07-29 08:32:33 +02:00
_cheat "$@"