From 7d1c6e093574742ddf80d2d467a49ae7f1c44bfc Mon Sep 17 00:00:00 2001 From: Jordan Russell Date: Sun, 12 Dec 2021 00:15:13 -0800 Subject: [PATCH 1/3] Add bash and zsh completions It can be difficult for shell users to type in all the command line arguments they want unaided, especially when it comes to timezone names. This patch makes it easier to use undertime by adding tab completion for bash and zsh users. The completion scripts don't add any dependencies not already in undertime as far as I am aware. This patch adds new 3 files and a new directory. *extra/undertime: Completion file for bash. *extra/_undertime: Completion file for zsh. *debian/undertime.install: Install completion files. --- debian/undertime.install | 2 ++ extra/_undertime | 38 +++++++++++++++++++++++ extra/undertime | 65 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 debian/undertime.install create mode 100644 extra/_undertime create mode 100644 extra/undertime diff --git a/debian/undertime.install b/debian/undertime.install new file mode 100644 index 0000000..72f2047 --- /dev/null +++ b/debian/undertime.install @@ -0,0 +1,2 @@ +extra/_undertime /usr/share/zsh/vendor-completions +extra/undertime /usr/share/bash-completion/completions \ No newline at end of file diff --git a/extra/_undertime b/extra/_undertime new file mode 100644 index 0000000..c3b745f --- /dev/null +++ b/extra/_undertime @@ -0,0 +1,38 @@ +#compdef undertime + +_timezones() { + python3 -c "import pytz; print(' '.join(pytz.all_timezones))" +} + +_undertime() { + _arguments \ + {-t,--timezones}":*:timezones:( $(_timezones) )" \ + '--config+[yaml config file]:filename:_files -g "*.(yaml|yml)"' \ + {-s,--start}+'[start of the working day]:hour:' \ + {-e,--end}'[end of the working day]:hour:' \ + {-d,--date}'[target date for the meeting, supports arbitrary dates like "in two weeks"]:string:' \ + "--no-colors[don\'t don't show colors]" \ + '--colors[show colors]' \ + '--default-zone[show current time zone first]' \ + "--no-default-zone[don't show current time zone first]" \ + '--unique[deduplicate time zone offsets]' \ + "--no-unique[don't show current time zone first]" \ + '--overlap[show zones overlap]' \ + "--no-overlap[don't show zones overlap]" \ + '--overlap-min[minimum overlap between zones]:number:' \ + '--truncate[short column headers]' \ + "--no-truncate[don't shorten column headers]" \ + '--abbreviate[(deprecated)]' \ + "--no-abbreviate[(deprecated)]" \ + '--table[show the table]' \ + "--no-table[hide the table]" \ + '--debug[enable debugging messages]' \ + {-f,--format}+'[format string for the tabulate package to format the main table]:string:(fancy_grid github grid html jira latex latex_booktabs latex_raw mediawiki moinmoin orgtbl pipe plain presto pretty psql rst simple textile tsv youtrack fancy_grid_nogap)' \ + {-v,--verbose}'[enable verbose messages]' \ + {-l,--list-zones}'[show valid time zones and exit]' \ + {-V,--version}'[print version number and exit]' \ + {-h,--help}'[show summary of options and defaults]' \ + '--selftest[run test suite]' +} + +_undertime "$@" diff --git a/extra/undertime b/extra/undertime new file mode 100644 index 0000000..635c49f --- /dev/null +++ b/extra/undertime @@ -0,0 +1,65 @@ +# bash completion for undertime -*- shell-script -*- + +_timezones () { + python3 -c "import pytz; print(' '.join(pytz.all_timezones))" +} + +_undertime () { + local cur prev words + cur=$2 + prev=$3 + COMPREPLY=() + + words=( ${COMP_LINE[@]} ) + # If the last option argument is -t or --timezones and the point is at + # a position after -t or --timezones then complete timezone names + # otherwise complete regular options + for ((i=${#words[@]} - 1; i > 0; i--)); do + if [[ ${words[i]} == -* ]]; then + if [[ ${words[i]} == @(-t|--timezones) ]]; then + rest=${COMP_LINE#*${words[i]}} + if (( $COMP_POINT > ${#rest} )); then + COMPREPLY=( $(compgen -W "$(_timezones)" -- $cur) ) + return 0 + fi + fi + # give up if we have an option other than -t or --timezones + break + fi + done + + case "$prev" in + --config) + _filedir @(yml|yaml) + return 0 + ;; + --format|-f) + COMPREPLY=( $(compgen -W 'fancy_grid github grid html jira \ + latex latex_booktabs latex_raw mediawiki \ + moinmoin orgtbl pipe plain presto pretty \ + psql rst simple textile tsv youtrack \ + fancy_grid_nogap' -- $cur ) ) + return 0 + ;; + --start|-s) + ;& + --end|-e) + ;& + --date|-d) + ;& + --overlap-min) + return 0 + ;; + esac + COMPREPLY=( $( compgen -W '-t --timezones --config \ + -s --start -e --end -d --date --no-colors --colors --default-zone \ + --no-default-zone --unique --no-unique --overlap --no-overlap \ + --overlap-min --truncate --no-truncate --abbreviate --no-abbreviate \ + --table --no-table --debug -f --format -v --verbose -l --list-zones \ + -V --version -h --help --selftest' -- $cur) ) + + return 0 +} && + complete -F _undertime undertime + +# ex filetype=sh -- GitLab From 0100fccc6b8193fc1500d728e819024308e7d6cf Mon Sep 17 00:00:00 2001 From: Jordan Russell Date: Mon, 13 Dec 2021 12:30:46 -0800 Subject: [PATCH 2/3] Remove deprecated options from completion scripts -d,--date and --(no)-abbreviate are deprecated options and so should avoid being completed --- extra/_undertime | 5 +---- extra/undertime | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/extra/_undertime b/extra/_undertime index c3b745f..dff460f 100644 --- a/extra/_undertime +++ b/extra/_undertime @@ -6,11 +6,10 @@ _timezones() { _undertime() { _arguments \ - {-t,--timezones}":*:timezones:( $(_timezones) )" \ + {-t,--timezones}"[time zones to show]"":*:timezones:( $(_timezones) )" \ '--config+[yaml config file]:filename:_files -g "*.(yaml|yml)"' \ {-s,--start}+'[start of the working day]:hour:' \ {-e,--end}'[end of the working day]:hour:' \ - {-d,--date}'[target date for the meeting, supports arbitrary dates like "in two weeks"]:string:' \ "--no-colors[don\'t don't show colors]" \ '--colors[show colors]' \ '--default-zone[show current time zone first]' \ @@ -22,8 +21,6 @@ _undertime() { '--overlap-min[minimum overlap between zones]:number:' \ '--truncate[short column headers]' \ "--no-truncate[don't shorten column headers]" \ - '--abbreviate[(deprecated)]' \ - "--no-abbreviate[(deprecated)]" \ '--table[show the table]' \ "--no-table[hide the table]" \ '--debug[enable debugging messages]' \ diff --git a/extra/undertime b/extra/undertime index 635c49f..4ffaa83 100644 --- a/extra/undertime +++ b/extra/undertime @@ -45,16 +45,14 @@ _undertime () { ;& --end|-e) ;& - --date|-d) - ;& --overlap-min) return 0 ;; esac COMPREPLY=( $( compgen -W '-t --timezones --config \ - -s --start -e --end -d --date --no-colors --colors --default-zone \ + -s --start -e --end --no-colors --colors --default-zone \ --no-default-zone --unique --no-unique --overlap --no-overlap \ - --overlap-min --truncate --no-truncate --abbreviate --no-abbreviate \ + --overlap-min --truncate --no-truncate \ --table --no-table --debug -f --format -v --verbose -l --list-zones \ -V --version -h --help --selftest' -- $cur) ) -- GitLab From e5e3cbd3827b8e592e563be373fa38fc5beacafb Mon Sep 17 00:00:00 2001 From: Jordan Russell Date: Tue, 14 Dec 2021 12:32:34 -0800 Subject: [PATCH 3/3] Remove extra quotation from zsh completion file --- extra/_undertime | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/_undertime b/extra/_undertime index dff460f..981db6a 100644 --- a/extra/_undertime +++ b/extra/_undertime @@ -6,7 +6,7 @@ _timezones() { _undertime() { _arguments \ - {-t,--timezones}"[time zones to show]"":*:timezones:( $(_timezones) )" \ + {-t,--timezones}"[time zones to show]:*:timezones:( $(_timezones) )" \ '--config+[yaml config file]:filename:_files -g "*.(yaml|yml)"' \ {-s,--start}+'[start of the working day]:hour:' \ {-e,--end}'[end of the working day]:hour:' \ -- GitLab