Skip to content

Commit

Permalink
feat(completions): add Bash and fish
Browse files Browse the repository at this point in the history
  • Loading branch information
dbohdan committed Dec 26, 2024
1 parent 17363b9 commit d10b0df
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
10 changes: 10 additions & 0 deletions completions/install.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /usr/bin/env fish

cd "$(path dirname "$(status filename)")"

set --local src memsparkline.fish
set --local dst $__fish_config_dir/completions/

printf 'copying "%s" to "%s"\n' $src $dst

cp $src $dst
41 changes: 41 additions & 0 deletions completions/memsparkline.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
_memsparkline() {
local cur prev opts

COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD - 1]}
opts='-h --help -v --version -d --dump -l --length -m --mem-format -n --newlines -o --output -q --quiet -r --record -s --sample -t --time-format -w --wait'

case "${prev}" in
-d | --dump | -o | --output)
COMPREPLY=($(compgen -f -- "${cur}"))
return 0
;;
-l | --length)
COMPREPLY=($(compgen -W "20 40 60 80" -- "${cur}"))
return 0
;;
-r | --record | -s | --sample | -w | --wait)
COMPREPLY=($(compgen -W "100 200 500 1000" -- "${cur}"))
return 0
;;
-m | --mem-format)
COMPREPLY=($(compgen -W "%.0f %.1f %.2f" -- "${cur}"))
return 0
;;
-t | --time-format)
COMPREPLY=($(compgen -W "%d:%02d:%04.1f" -- "${cur}"))
return 0
;;
esac

if [[ ${cur} == -* ]]; then
COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
return 0
fi

# Complete with commands if no other completion applies.
COMPREPLY=($(compgen -c -- "${cur}"))
}

complete -F _memsparkline memsparkline
15 changes: 15 additions & 0 deletions completions/memsparkline.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
complete -c memsparkline -s h -l help -d 'Print help message and exit'
complete -c memsparkline -s v -l version -d 'Print version number and exit'
complete -c memsparkline -s d -l dump -d 'File to append memory usage history to' -r
complete -c memsparkline -s l -l length -d 'Sparkline length' -r -a "20 40 60 80"
complete -c memsparkline -s m -l mem-format -d 'Format string for memory amounts' -r -a "%.0f %.1f %.2f"
complete -c memsparkline -s n -l newlines -d 'Print new sparkline on new line'
complete -c memsparkline -s o -l output -d 'Output file to append to' -r
complete -c memsparkline -s q -l quiet -d 'Do not print sparklines'
complete -c memsparkline -s r -l record -d 'How frequently to record memory usage in ms' -r -a "100 200 500 1000"
complete -c memsparkline -s s -l sample -d 'How frequently to sample memory usage in ms' -r -a "100 200 500 1000"
complete -c memsparkline -s t -l time-format -d 'Format string for run time' -r -a "%d:%02d:%04.1f"
complete -c memsparkline -s w -l wait -d 'Set sample and record time simultaneously' -r -a "100 200 500 1000"

# Complete with available commands.
complete -c memsparkline -n __fish_is_first_token -a "(__fish_complete_command)"

0 comments on commit d10b0df

Please sign in to comment.