From e84ace339be93f93df83435714a7b412f27bd92c Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 28 Dec 2021 18:11:37 +0900 Subject: [PATCH 1/8] lib/utils: Rename logging functions --- lib/omb-deprecate.sh | 13 ++++ lib/utils.sh | 137 ++++++++++++++++++++----------------------- 2 files changed, 77 insertions(+), 73 deletions(-) diff --git a/lib/omb-deprecate.sh b/lib/omb-deprecate.sh index f3e8378..7e521eb 100644 --- a/lib/omb-deprecate.sh +++ b/lib/omb-deprecate.sh @@ -19,3 +19,16 @@ is_alias() { local base_dir=$1 name=$2 [[ -f $base_dir/aliases/$name/$name.aliases.sh ]] } + + +# lib/utils.sh -- Logging functions +_omb_util_defun_deprecate 20000 type_exists _omb_util_binary_exists + +_omb_util_defun_deprecate 20000 _omb_log_header e_header +_omb_util_defun_deprecate 20000 _omb_log_arrow e_arrow +_omb_util_defun_deprecate 20000 _omb_log_success e_success +_omb_util_defun_deprecate 20000 _omb_log_error e_error +_omb_util_defun_deprecate 20000 _omb_log_warning e_warning +_omb_util_defun_deprecate 20000 _omb_log_underline e_underline +_omb_util_defun_deprecate 20000 _omb_log_bold e_bold +_omb_util_defun_deprecate 20000 _omb_log_note e_note diff --git a/lib/utils.sh b/lib/utils.sh index 3f3e7b0..65b8d46 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -94,78 +94,6 @@ function _omb_util_defun_deprecate { builtin eval -- "function $2 { $warning$3 \"\$@\"; }" } -# -# Set Colors -# -# Use colors, but only if connected to a terminal, and that terminal -# supports them. -if which tput >/dev/null 2>&1; then - ncolors=$(tput colors) -fi -if [[ -t 1 && $ncolors && ncolors -ge 8 ]]; then - bold=$(tput bold 2>/dev/null || tput md 2>/dev/null) - underline=$(tput smul 2>/dev/null || tput ul 2>/dev/null) - reset=$(tput sgr0 2>/dev/null || tput me 2>/dev/null) - red=$(tput setaf 1 2>/dev/null || tput AF 1 2>/dev/null) - green=$(tput setaf 2 2>/dev/null || tput AF 2 2>/dev/null) - yellow=$(tput setaf 3 2>/dev/null || tput AF 3 2>/dev/null) - blue=$(tput setaf 4 2>/dev/null || tput AF 4 2>/dev/null) - purple=$(tput setaf 171 2>/dev/null || tput AF 171 2>/dev/null) - tan=$(tput setaf 3 2>/dev/null || tput AF 3 2>/dev/null) -else - bold="" - underline="" - reset="" - red="" - green="" - yellow="" - blue="" - purple="" - tan="" -fi - -# -# Headers and Logging -# -e_header() { printf "\n${bold}${purple}========== %s ==========${reset}\n" "$@" -} -e_arrow() { printf "➜ %s\n" "$@" -} -e_success() { printf "${green}✔ %s${reset}\n" "$@" -} -e_error() { printf "${red}✖ %s${reset}\n" "$@" -} -e_warning() { printf "${tan}➜ %s${reset}\n" "$@" -} -e_underline() { printf "${underline}${bold}%s${reset}\n" "$@" -} -e_bold() { printf "${bold}%s${reset}\n" "$@" -} -e_note() { printf "${underline}${bold}${blue}Note:${reset} ${yellow}%s${reset}\n" "$@" -} - -# -# USAGE FOR SEEKING CONFIRMATION -# seek_confirmation "Ask a question" -# Credit: https://github.com/kevva/dotfiles -# -# if is_confirmed; then -# some action -# else -# some other action -# fi -# -seek_confirmation() { - printf "\\n${bold}%s${reset}" "$@" - read -p " (y/n) " -n 1 - printf "\\n" -} - -# Test whether the result of an 'ask' is a confirmation -is_confirmed() { - [[ $REPLY =~ ^[Yy]$ ]] -} - # # Test whether a command---either an alias, a keyword, a function, a builtin, # or a file---is defined. @@ -206,7 +134,70 @@ _omb_util_function_exists() { declare -F "$@" &>/dev/null # bash-3.2 } -_omb_util_defun_deprecate 20000 type_exists _omb_util_binary_exists + +# +# Set Colors +# +# Use colors, but only if connected to a terminal, and that terminal +# supports them. +if which tput >/dev/null 2>&1; then + ncolors=$(tput colors) +fi +if [[ -t 1 && $ncolors && ncolors -ge 8 ]]; then + bold=$(tput bold 2>/dev/null || tput md 2>/dev/null) + underline=$(tput smul 2>/dev/null || tput ul 2>/dev/null) + reset=$(tput sgr0 2>/dev/null || tput me 2>/dev/null) + red=$(tput setaf 1 2>/dev/null || tput AF 1 2>/dev/null) + green=$(tput setaf 2 2>/dev/null || tput AF 2 2>/dev/null) + yellow=$(tput setaf 3 2>/dev/null || tput AF 3 2>/dev/null) + blue=$(tput setaf 4 2>/dev/null || tput AF 4 2>/dev/null) + purple=$(tput setaf 171 2>/dev/null || tput AF 171 2>/dev/null) + tan=$(tput setaf 3 2>/dev/null || tput AF 3 2>/dev/null) +else + bold="" + underline="" + reset="" + red="" + green="" + yellow="" + blue="" + purple="" + tan="" +fi + +# +# Headers and Logging +# +_omb_log_header() { printf "\n${bold}${purple}========== %s ==========${reset}\n" "$@"; } +_omb_log_arrow() { printf "➜ %s\n" "$@"; } +_omb_log_success() { printf "${green}✔ %s${reset}\n" "$@"; } +_omb_log_error() { printf "${red}✖ %s${reset}\n" "$@"; } +_omb_log_warning() { printf "${tan}➜ %s${reset}\n" "$@"; } +_omb_log_underline() { printf "${underline}${bold}%s${reset}\n" "$@"; } +_omb_log_bold() { printf "${bold}%s${reset}\n" "$@"; } +_omb_log_note() { printf "${underline}${bold}${blue}Note:${reset} ${yellow}%s${reset}\n" "$@"; } + +# +# USAGE FOR SEEKING CONFIRMATION +# seek_confirmation "Ask a question" +# Credit: https://github.com/kevva/dotfiles +# +# if is_confirmed; then +# some action +# else +# some other action +# fi +# +seek_confirmation() { + printf "\\n${bold}%s${reset}" "$@" + read -p " (y/n) " -n 1 + printf "\\n" +} + +# Test whether the result of an 'ask' is a confirmation +is_confirmed() { + [[ $REPLY =~ ^[Yy]$ ]] +} # # Test which OS the user runs From 31f095f3ac7d9a6725b6646c35b131614833067f Mon Sep 17 00:00:00 2001 From: Jacob Hrbek Date: Wed, 24 Jul 2019 03:00:45 +0200 Subject: [PATCH 2/8] oh-my-bash: Show warning and fail for non-interactive shells Co-authored-by: Koichi Murase --- oh-my-bash.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/oh-my-bash.sh b/oh-my-bash.sh index 9b5dffb..83cf81a 100644 --- a/oh-my-bash.sh +++ b/oh-my-bash.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash # Bail out early if non-interactive -case $- in - *i*) ;; - *) return;; -esac +if [[ $- != *i* ]]; then + printf 'oh-my-bash: Shell is not interactive.\n' >&2 + return 1 +fi # Check for updates on initial load... if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then From b05f53558b8f6beaf10f3a108aa5f85d03608bc2 Mon Sep 17 00:00:00 2001 From: Jacob Hrbek Date: Wed, 24 Jul 2019 03:33:12 +0200 Subject: [PATCH 3/8] oh-my-bash: Quote parameter expansions properly --- oh-my-bash.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oh-my-bash.sh b/oh-my-bash.sh index 83cf81a..e1d36b4 100644 --- a/oh-my-bash.sh +++ b/oh-my-bash.sh @@ -8,7 +8,7 @@ fi # Check for updates on initial load... if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then - env OSH=$OSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT bash -f $OSH/tools/check_for_upgrade.sh + env OSH="$OSH" DISABLE_UPDATE_PROMPT="$DISABLE_UPDATE_PROMPT" bash -f "$OSH"/tools/check_for_upgrade.sh fi # Initializes Oh My Bash From eaa147afa6a3a37bd504a8b0d26fac6801335d21 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 28 Dec 2021 19:30:44 +0900 Subject: [PATCH 4/8] completions/brew: Protect against pathname expansions and refactor --- completions/brew.completion.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/completions/brew.completion.sh b/completions/brew.completion.sh index 50f6c08..a98aa11 100644 --- a/completions/brew.completion.sh +++ b/completions/brew.completion.sh @@ -1,9 +1,13 @@ -if which brew >/dev/null 2>&1; then - if [ -f `brew --prefix`/etc/bash_completion ]; then - . `brew --prefix`/etc/bash_completion - fi +if _omb_util_command_exists brew; then + _omb_completion_brew_prefix=$(brew --prefix) + if [[ $_omb_completion_brew_prefix ]]; then + if [[ -f $_omb_completion_brew_prefix/etc/bash_completion ]]; then + source "$_omb_completion_brew_prefix"/etc/bash_completion + fi - if [ -f `brew --prefix`/Library/Contributions/brew_bash_completion.sh ]; then - . `brew --prefix`/Library/Contributions/brew_bash_completion.sh + if [[ -f $_omb_completion_brew_prefix/Library/Contributions/brew_bash_completion.sh ]]; then + source "$_omb_completion_brew_prefix"/Library/Contributions/brew_bash_completion.sh + fi fi + unset -v _omb_completion_brew_prefix fi From 2027dd42a4f81685f505bf0c3b8d1f9e7976d8ba Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 28 Dec 2021 19:59:28 +0900 Subject: [PATCH 5/8] completions/salt: Fix quoting for "compgen -W" and others --- completions/salt.completion.sh | 224 ++++++++++++++++----------------- 1 file changed, 112 insertions(+), 112 deletions(-) diff --git a/completions/salt.completion.sh b/completions/salt.completion.sh index e8cb5b2..d42f423 100644 --- a/completions/salt.completion.sh +++ b/completions/salt.completion.sh @@ -13,7 +13,7 @@ _salt_get_grains(){ - if [ "$1" = 'local' ] ; then + if [ "$1" = 'local' ] ; then salt-call --out=txt -- grains.ls | sed 's/^.*\[//' | tr -d ",']" |sed 's:\([a-z0-9]\) :\1\: :g' else salt '*' --timeout 2 --out=txt -- grains.ls | sed 's/^.*\[//' | tr -d ",']" |sed 's:\([a-z0-9]\) :\1\: :g' @@ -22,23 +22,23 @@ _salt_get_grains(){ _salt_get_grain_values(){ if [ "$1" = 'local' ] ; then - salt-call --out=txt -- grains.item $1 |sed 's/^\S*:\s//' |grep -v '^\s*$' + salt-call --out=txt -- grains.item $1 |sed 's/^\S*:\s//' |grep -v '^\s*$' else - salt '*' --timeout 2 --out=txt -- grains.item $1 |sed 's/^\S*:\s//' |grep -v '^\s*$' + salt '*' --timeout 2 --out=txt -- grains.item $1 |sed 's/^\S*:\s//' |grep -v '^\s*$' fi } _salt(){ - local cur prev opts _salt_grains _salt_coms pprev ppprev + local cur prev opts pprev ppprev COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" if [ ${COMP_CWORD} -gt 2 ]; then - pprev="${COMP_WORDS[COMP_CWORD-2]}" + pprev="${COMP_WORDS[COMP_CWORD-2]}" fi if [ ${COMP_CWORD} -gt 3 ]; then - ppprev="${COMP_WORDS[COMP_CWORD-3]}" + ppprev="${COMP_WORDS[COMP_CWORD-3]}" fi opts="-h --help -d --doc --documentation --version --versions-report -c \ @@ -50,7 +50,7 @@ _salt(){ --out=raw --out=highstate --out=key --out=txt --no-color --out-indent= " if [[ "${cur}" == -* ]] ; then - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=($(compgen -W '$opts' -- "$cur")) return 0 fi @@ -58,67 +58,68 @@ _salt(){ case "${pprev}" in -G|--grain|--grain-pcre) if [ "${cur}" = ":" ]; then - COMPREPLY=($(compgen -W "`_salt_get_grain_values ${prev}`" )) + COMPREPLY=($(compgen -W '$(_salt_get_grain_values "$prev")')) return 0 fi ;; - esac + esac case "${ppprev}" in -G|--grain|--grain-pcre) if [ "${prev}" = ":" ]; then - COMPREPLY=( $(compgen -W "`_salt_get_grain_values ${pprev}`" -- ${cur}) ) + COMPREPLY=($(compgen -W '$(_salt_get_grain_values "$pprev")' -- "$cur")) return 0 fi ;; - esac - + esac + if [ "${cur}" = "=" ] && [[ "${prev}" == --* ]]; then - cur="" + cur="" fi if [ "${prev}" = "=" ] && [[ "${pprev}" == --* ]]; then prev="${pprev}" fi - + case "${prev}" in - + -c|--config) - COMPREPLY=($(compgen -f -- ${cur})) + COMPREPLY=($(compgen -f -- "$cur")) return 0 ;; salt) - COMPREPLY=($(compgen -W "\'*\' ${opts} `salt-key --no-color -l acc`" -- ${cur})) + COMPREPLY=($(compgen -W "\'*\' \$opts \$(salt-key --no-color -l acc)" -- "$cur")) return 0 ;; - -E|--pcre) - COMPREPLY=($(compgen -W "`salt-key --no-color -l acc`" -- ${cur})) + -E|--pcre) + COMPREPLY=($(compgen -W '$(salt-key --no-color -l acc)' -- "$cur")) return 0 ;; -G|--grain|--grain-pcre) - COMPREPLY=($(compgen -W "$(_salt_get_grains)" -- ${cur})) + COMPREPLY=($(compgen -W '$(_salt_get_grains)' -- "$cur")) return 0 - ;; + ;; -C|--compound) COMPREPLY=() # TODO: finish this one? how? return 0 ;; -t|--timeout) - COMPREPLY=($( compgen -W "1 2 3 4 5 6 7 8 9 10 15 20 30 40 60 90 120 180" -- ${cur})) + COMPREPLY=($(compgen -W "1 2 3 4 5 6 7 8 9 10 15 20 30 40 60 90 120 180" -- "$cur")) return 0 ;; -b|--batch|--batch-size) COMPREPLY=($(compgen -W "1 2 3 4 5 6 7 8 9 10 15 20 30 40 50 60 70 80 90 100 120 150 200")) return 0 ;; - -N|--nodegroup) - MASTER_CONFIG='/etc/salt/master' - COMPREPLY=($(compgen -W "`awk -F ':' 'BEGIN {print_line = 0}; /^nodegroups/ {print_line = 1;getline } print_line && /^ */ {print $1} /^[^ ]/ {print_line = 0}' <${MASTER_CONFIG}`" -- ${cur})) - return 0 - ;; + -N|--nodegroup) + local MASTER_CONFIG='/etc/salt/master' + local all=$(awk -F ':' 'BEGIN {print_line = 0}; /^nodegroups/ {print_line = 1;getline } print_line && /^ */ {print $1} /^[^ ]/ {print_line = 0}' < "$MASTER_CONFIG") + COMPREPLY=($(compgen -W '$all' -- "$cur")) + return 0 + ;; esac - _salt_coms="$(salt '*' --timeout 2 --out=txt -- sys.list_functions | sed 's/^.*\[//' | tr -d ",']" )" - all="${opts} ${_salt_coms}" - COMPREPLY=( $(compgen -W "${all}" -- ${cur}) ) + local _salt_coms=$(salt '*' --timeout 2 --out=txt -- sys.list_functions | sed 's/^.*\[//' | tr -d ",']" ) + local all="${opts} ${_salt_coms}" + COMPREPLY=($(compgen -W '$all' -- "$cur")) return 0 } @@ -133,8 +134,8 @@ _saltkey(){ prev="${COMP_WORDS[COMP_CWORD-1]}" opts="-c --config-dir= -h --help --version --versions-report -q --quiet \ -y --yes --gen-keys= --gen-keys-dir= --keysize= --key-logfile= \ - -l --list= -L --list-all -a --accept= -A --accept-all \ - -r --reject= -R --reject-all -p --print= -P --print-all \ + -l --list= -L --list-all -a --accept= -A --accept-all \ + -r --reject= -R --reject-all -p --print= -P --print-all \ -d --delete= -D --delete-all -f --finger= -F --finger-all \ --out=pprint --out=yaml --out=overstatestage --out=json --out=raw \ --out=highstate --out=key --out=txt --no-color --out-indent= " @@ -145,65 +146,65 @@ _saltkey(){ ppprev="${COMP_WORDS[COMP_CWORD-3]}" fi if [[ "${cur}" == -* ]] ; then - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=($(compgen -W '$opts' -- "$cur")) return 0 fi if [ "${cur}" = "=" ] && [[ "${prev}" == --* ]]; then - cur="" + cur="" fi if [ "${prev}" = "=" ] && [[ "${pprev}" == --* ]]; then prev="${pprev}" fi - case "${prev}" in + case "${prev}" in -a|--accept) - COMPREPLY=($(compgen -W "$(salt-key -l un --no-color; salt-key -l rej --no-color)" -- ${cur})) + COMPREPLY=($(compgen -W '$(salt-key -l un --no-color; salt-key -l rej --no-color)' -- "$cur")) return 0 ;; -r|--reject) - COMPREPLY=($(compgen -W "$(salt-key -l acc --no-color)" -- ${cur})) + COMPREPLY=($(compgen -W '$(salt-key -l acc --no-color)' -- "$cur")) return 0 ;; -d|--delete) - COMPREPLY=($(compgen -W "$(salt-key -l acc --no-color; salt-key -l un --no-color; salt-key -l rej --no-color)" -- ${cur})) + COMPREPLY=($(compgen -W '$(salt-key -l acc --no-color; salt-key -l un --no-color; salt-key -l rej --no-color)' -- "$cur")) return 0 ;; -c|--config) - COMPREPLY=($(compgen -f -- ${cur})) + COMPREPLY=($(compgen -f -- "$cur")) return 0 ;; --keysize) - COMPREPLY=($(compgen -W "2048 3072 4096 5120 6144" -- ${cur})) + COMPREPLY=($(compgen -W "2048 3072 4096 5120 6144" -- "$cur")) return 0 ;; - --gen-keys) + --gen-keys) return 0 ;; --gen-keys-dir) - COMPREPLY=($(compgen -d -- ${cur})) + COMPREPLY=($(compgen -d -- "$cur")) return 0 ;; -p|--print) - COMPREPLY=($(compgen -W "$(salt-key -l acc --no-color; salt-key -l un --no-color; salt-key -l rej --no-color)" -- ${cur})) + COMPREPLY=($(compgen -W '$(salt-key -l acc --no-color; salt-key -l un --no-color; salt-key -l rej --no-color)' -- "$cur")) return 0 ;; -l|--list) - COMPREPLY=($(compgen -W "pre un acc accepted unaccepted rej rejected all" -- ${cur})) + COMPREPLY=($(compgen -W "pre un acc accepted unaccepted rej rejected all" -- "$cur")) return 0 ;; --accept-all) - return 0 + return 0 ;; esac - COMPREPLY=($(compgen -W "${opts} " -- ${cur})) + COMPREPLY=($(compgen -W '$opts' -- "$cur")) return 0 } complete -F _saltkey salt-key _saltcall(){ - local cur prev opts _salt_coms pprev ppprev + local cur prev opts pprev ppprev COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" @@ -218,37 +219,37 @@ _saltcall(){ ppprev="${COMP_WORDS[COMP_CWORD-3]}" fi if [[ "${cur}" == -* ]] ; then - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=($(compgen -W '$opts' -- "$cur")) return 0 fi - + if [ "${cur}" = "=" ] && [[ ${prev} == --* ]]; then cur="" fi if [ "${prev}" = "=" ] && [[ ${pprev} == --* ]]; then prev="${pprev}" fi - + case ${prev} in -m|--module-dirs) - COMPREPLY=( $(compgen -d ${cur} )) - return 0 - ;; - -l|--log-level) - COMPREPLY=( $(compgen -W "info none garbage trace warning error debug" -- ${cur})) - return 0 - ;; - -g|grains) + COMPREPLY=($(compgen -d -- "$cur")) return 0 - ;; - salt-call) - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) - return 0 - ;; + ;; + -l|--log-level) + COMPREPLY=($(compgen -W "info none garbage trace warning error debug" -- "$cur")) + return 0 + ;; + -g|grains) + return 0 + ;; + salt-call) + COMPREPLY=($(compgen -W '$opts' -- "$cur")) + return 0 + ;; esac - _salt_coms="$(salt-call --out=txt -- sys.list_functions|sed 's/^.*\[//' | tr -d ",']" )" - COMPREPLY=( $(compgen -W "${opts} ${_salt_coms}" -- ${cur} )) + local _salt_coms=$(salt-call --out=txt -- sys.list_functions|sed 's/^.*\[//' | tr -d ",']") + COMPREPLY=($(compgen -W '$opts $_salt_coms' -- "$cur")) return 0 } @@ -262,68 +263,67 @@ _saltcp(){ prev="${COMP_WORDS[COMP_CWORD-1]}" opts="-t --timeout= -s --static -b --batch= --batch-size= \ -h --help --version --versions-report -c --config-dir= \ - -E --pcre -L --list -G --grain --grain-pcre -N --nodegroup \ + -E --pcre -L --list -G --grain --grain-pcre -N --nodegroup \ -R --range -C --compound -I --pillar \ --out=pprint --out=yaml --out=overstatestage --out=json --out=raw \ --out=highstate --out=key --out=txt --no-color --out-indent= " if [[ "${cur}" == -* ]] ; then - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=($(compgen -W '$opts' -- "$cur")) return 0 fi - + if [ "${cur}" = "=" ] && [[ "${prev}" == --* ]]; then - cur="" + cur="" fi if [ "${prev}" = "=" ] && [[ "${pprev}" == --* ]]; then prev=${pprev} fi - - case ${prev} in - salt-cp) - COMPREPLY=($(compgen -W "${opts} `salt-key -l acc --no-color`" -- ${cur})) - return 0 - ;; - -t|--timeout) - # those numbers are just a hint - COMPREPLY=($(compgen -W "2 3 4 8 10 15 20 25 30 40 60 90 120 180 240 300" -- ${cur} )) - return 0 - ;; - -E|--pcre) - COMPREPLY=($(compgen -W "`salt-key -l acc --no-color`" -- ${cur})) - return 0 - ;; - -L|--list) - # IMPROVEMENTS ARE WELCOME - prefpart="${cur%,*}," - postpart=${cur##*,} - filt="^\($(echo ${cur}| sed 's:,:\\|:g')\)$" - helper=($(salt-key -l acc --no-color | grep -v "${filt}" | sed "s/^/${prefpart}/")) - COMPREPLY=($(compgen -W "${helper[*]}" -- ${cur})) - return 0 - ;; - -G|--grain|--grain-pcre) - COMPREPLY=($(compgen -W "$(_salt_get_grains)" -- ${cur})) + case ${prev} in + salt-cp) + COMPREPLY=($(compgen -W '$opts $(salt-key -l acc --no-color)' -- "$cur")) return 0 - ;; - # FIXME - -R|--range) - # FIXME ?? - return 0 - ;; - -C|--compound) - # FIXME ?? - return 0 - ;; - -c|--config) - COMPREPLY=($(compgen -f -- ${cur})) - return 0 - ;; + ;; + -t|--timeout) + # those numbers are just a hint + COMPREPLY=($(compgen -W "2 3 4 8 10 15 20 25 30 40 60 90 120 180 240 300" -- "$cur")) + return 0 + ;; + -E|--pcre) + COMPREPLY=($(compgen -W '$(salt-key -l acc --no-color)' -- "$cur")) + return 0 + ;; + -L|--list) + # IMPROVEMENTS ARE WELCOME + prefpart="${cur%,*}," + postpart=${cur##*,} + filt="^\($(echo ${cur}| sed 's:,:\\|:g')\)$" + helper=($(salt-key -l acc --no-color | grep -v "${filt}" | sed "s/^/${prefpart}/")) + COMPREPLY=($(compgen -W '"${helper[@]}"' -- "$cur")) + + return 0 + ;; + -G|--grain|--grain-pcre) + COMPREPLY=($(compgen -W '$(_salt_get_grains)' -- "$cur")) + return 0 + ;; + # FIXME + -R|--range) + # FIXME ?? + return 0 + ;; + -C|--compound) + # FIXME ?? + return 0 + ;; + -c|--config) + COMPREPLY=($(compgen -f -- "$cur")) + return 0 + ;; esac - + # default is using opts: - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + COMPREPLY=($(compgen -W '$opts' -- "$cur")) } complete -F _saltcp salt-cp - From a085f452fb6f03f82392457a924b76b6ac960dd5 Mon Sep 17 00:00:00 2001 From: Jacob Hrbek Date: Thu, 15 Aug 2019 10:03:08 +0000 Subject: [PATCH 6/8] themes/agnoster: Use the POSIX command substitutions Co-authored-by: Koichi Murase --- themes/agnoster/agnoster.theme.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/agnoster/agnoster.theme.sh b/themes/agnoster/agnoster.theme.sh index dee03ee..ebcd4c7 100755 --- a/themes/agnoster/agnoster.theme.sh +++ b/themes/agnoster/agnoster.theme.sh @@ -36,7 +36,7 @@ # export THEME=$HOME/.bash/themes/agnoster-bash/agnoster.bash # if [[ -f $THEME ]]; then -# export DEFAULT_USER=`whoami` +# export DEFAULT_USER=$(whoami) # source $THEME # fi @@ -227,7 +227,7 @@ prompt_virtualenv() { # Context: user@hostname (who am I and where am I) prompt_context() { - local user=`whoami` + local user=$(whoami) if [[ $user != $DEFAULT_USER || -n $SSH_CLIENT ]]; then prompt_segment black default "$user@\h" From 85211c1f7689f0fc206f3db0047616cc017c097d Mon Sep 17 00:00:00 2001 From: Jacob Hrbek Date: Thu, 15 Aug 2019 10:04:38 +0000 Subject: [PATCH 7/8] themes/rjorgenson: Use the POSIX command substitution --- themes/rjorgenson/rjorgenson.theme.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/rjorgenson/rjorgenson.theme.sh b/themes/rjorgenson/rjorgenson.theme.sh index 5c0dbb8..2375657 100644 --- a/themes/rjorgenson/rjorgenson.theme.sh +++ b/themes/rjorgenson/rjorgenson.theme.sh @@ -50,7 +50,7 @@ function is_integer() { # helper function for todo-txt-count todo_txt_count() { if `hash todo.sh 2>&-`; then # is todo.sh installed - count=`todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }'` + count=$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }') if is_integer $count; then # did we get a sane answer back echo "${BRACKET_COLOR}[${STRING_COLOR}T:$count${BRACKET_COLOR}]$normal" fi From 8780308a4f7586edab9fc8ec18b7c2bb1a04b8ba Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 28 Dec 2021 20:29:22 +0900 Subject: [PATCH 8/8] themes: Fix wrong usage of command substitutions in conditions --- themes/agnoster/agnoster.theme.sh | 2 +- themes/rana/rana.theme.sh | 6 +++--- themes/rjorgenson/rjorgenson.theme.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/themes/agnoster/agnoster.theme.sh b/themes/agnoster/agnoster.theme.sh index ebcd4c7..b1eb2d3 100755 --- a/themes/agnoster/agnoster.theme.sh +++ b/themes/agnoster/agnoster.theme.sh @@ -249,7 +249,7 @@ git_status_dirty() { # Git: branch/detached head, dirty status prompt_git() { local ref dirty - if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then + if git rev-parse --is-inside-work-tree &>/dev/null; then ZSH_THEME_GIT_PROMPT_DIRTY='±' dirty=$(git_status_dirty) ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)" diff --git a/themes/rana/rana.theme.sh b/themes/rana/rana.theme.sh index ab1d660..5ab804e 100644 --- a/themes/rana/rana.theme.sh +++ b/themes/rana/rana.theme.sh @@ -137,12 +137,12 @@ prompt_git() { git update-index --really-refresh -q &>/dev/null; # Check for uncommitted changes in the index. - if ! $(git diff --quiet --ignore-submodules --cached); then + if ! git diff --quiet --ignore-submodules --cached; then s+='+'; fi; # Check for unstaged changes. - if ! $(git diff-files --quiet --ignore-submodules --); then + if ! git diff-files --quiet --ignore-submodules --; then s+='!'; fi; @@ -152,7 +152,7 @@ prompt_git() { fi; # Check for stashed files. - if $(git rev-parse --verify refs/stash &>/dev/null); then + if git rev-parse --verify refs/stash &>/dev/null; then s+='$'; fi; diff --git a/themes/rjorgenson/rjorgenson.theme.sh b/themes/rjorgenson/rjorgenson.theme.sh index 2375657..a0635ce 100644 --- a/themes/rjorgenson/rjorgenson.theme.sh +++ b/themes/rjorgenson/rjorgenson.theme.sh @@ -49,7 +49,7 @@ function is_integer() { # helper function for todo-txt-count } todo_txt_count() { - if `hash todo.sh 2>&-`; then # is todo.sh installed + if _omb_util_command_exists todo.sh; then # is todo.sh installed count=$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }') if is_integer $count; then # did we get a sane answer back echo "${BRACKET_COLOR}[${STRING_COLOR}T:$count${BRACKET_COLOR}]$normal"