diff --git a/clean_files.txt b/clean_files.txt index 1c205381ec..49bbe93720 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -160,6 +160,7 @@ themes/brainy themes/brunton themes/candy themes/clean +themes/doubletime themes/easy themes/elixr themes/essential @@ -175,7 +176,7 @@ themes/pete themes/powerline themes/pure themes/purity - +themes/rjorgenson # vendor init files # diff --git a/completion/available/fabric.completion.bash b/completion/available/fabric.completion.bash index a8984d9cc3..163a479b80 100644 --- a/completion/available/fabric.completion.bash +++ b/completion/available/fabric.completion.bash @@ -31,7 +31,6 @@ # https://github.com/ricobl/dotfiles/blob/master/bin/fab_bash_completion # - # Use cache files for fab tasks or not. # If set to "false" command "fab --shortlist" will be executed every time. export FAB_COMPLETION_CACHE_TASKS=true @@ -39,95 +38,92 @@ export FAB_COMPLETION_CACHE_TASKS=true # File name where tasks cache will be stored (in current dir). export FAB_COMPLETION_CACHED_TASKS_FILENAME=".fab_tasks~" - # Set command to get time of last file modification as seconds since Epoch case "$OSTYPE" in - 'darwin'*|'freebsd'*) - __FAB_COMPLETION_MTIME_COMMAND="stat -f '%m'" - ;; - *) - __FAB_COMPLETION_MTIME_COMMAND="stat -c '%Y'" - ;; + 'darwin'* | 'freebsd'*) + __FAB_COMPLETION_MTIME_COMMAND="stat -f '%m'" + ;; + *) + __FAB_COMPLETION_MTIME_COMMAND="stat -c '%Y'" + ;; esac - # # Get time of last fab cache file modification as seconds since Epoch # function __fab_chache_mtime() { - ${__FAB_COMPLETION_MTIME_COMMAND} \ - $FAB_COMPLETION_CACHED_TASKS_FILENAME | xargs -n 1 expr + ${__FAB_COMPLETION_MTIME_COMMAND} \ + $FAB_COMPLETION_CACHED_TASKS_FILENAME | xargs -n 1 expr } - # # Get time of last fabfile file/module modification as seconds since Epoch # function __fab_fabfile_mtime() { - local f="fabfile" - if [[ -e "$f.py" ]]; then - ${__FAB_COMPLETION_MTIME_COMMAND} "$f.py" | xargs -n 1 expr - else - # Suppose that it's a fabfile dir - find $f/*.py -exec ${__FAB_COMPLETION_MTIME_COMMAND} {} + \ - | xargs -n 1 expr | sort -n -r | head -1 - fi + local f="fabfile" + if [[ -e "$f.py" ]]; then + ${__FAB_COMPLETION_MTIME_COMMAND} "$f.py" | xargs -n 1 expr + else + # Suppose that it's a fabfile dir + find $f/*.py -exec ${__FAB_COMPLETION_MTIME_COMMAND} {} + \ + | xargs -n 1 expr | sort -n -r | head -1 + fi } - # # Completion for "fab" command # function __fab_completion() { - # Return if "fab" command doesn't exists - [[ -e `which fab 2> /dev/null` ]] || return 0 - - # Variables to hold the current word and possible matches - local cur="${COMP_WORDS[COMP_CWORD]}" - local opts=() - - # Generate possible matches and store them in variable "opts" - case "${cur}" in - -*) - if [[ -z "${__FAB_COMPLETION_LONG_OPT}" ]]; then - export __FAB_COMPLETION_LONG_OPT=$( - fab --help | grep -E -o "\-\-[A-Za-z_\-]+\=?" | sort -u) - fi - opts="${__FAB_COMPLETION_LONG_OPT}" - ;; - - # Completion for short options is not nessary. - # It's left here just for history. - # -*) - # if [[ -z "${__FAB_COMPLETION_SHORT_OPT}" ]]; then - # export __FAB_COMPLETION_SHORT_OPT=$( - # fab --help | grep -E -o "^ +\-[A-Za-z_\]" | sort -u) - # fi - # opts="${__FAB_COMPLETION_SHORT_OPT}" - # ;; - - *) - # If "fabfile.py" or "fabfile" dir with "__init__.py" file exists - local f="fabfile" - if [[ -e "$f.py" || (-d "$f" && -e "$f/__init__.py") ]]; then - # Build a list of the available tasks - if $FAB_COMPLETION_CACHE_TASKS; then - # If use cache - if [[ ! -s ${FAB_COMPLETION_CACHED_TASKS_FILENAME} || - $(__fab_fabfile_mtime) -gt $(__fab_chache_mtime) ]]; then - fab --shortlist > ${FAB_COMPLETION_CACHED_TASKS_FILENAME} \ - 2> /dev/null - fi - opts=$(cat ${FAB_COMPLETION_CACHED_TASKS_FILENAME}) - else - # Without cache - opts=$(fab --shortlist 2> /dev/null) - fi - fi - ;; - esac - - # Set possible completions - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + # Return if "fab" command doesn't exists + [[ -e $(which fab 2> /dev/null) ]] || return 0 + + # Variables to hold the current word and possible matches + local cur="${COMP_WORDS[COMP_CWORD]}" + local opts=() + + # Generate possible matches and store them in variable "opts" + case "${cur}" in + -*) + if [[ -z "${__FAB_COMPLETION_LONG_OPT}" ]]; then + export __FAB_COMPLETION_LONG_OPT=$( + fab --help | grep -E -o "\-\-[A-Za-z_\-]+\=?" | sort -u + ) + fi + opts="${__FAB_COMPLETION_LONG_OPT}" + ;; + + # Completion for short options is not nessary. + # It's left here just for history. + # -*) + # if [[ -z "${__FAB_COMPLETION_SHORT_OPT}" ]]; then + # export __FAB_COMPLETION_SHORT_OPT=$( + # fab --help | grep -E -o "^ +\-[A-Za-z_\]" | sort -u) + # fi + # opts="${__FAB_COMPLETION_SHORT_OPT}" + # ;; + + *) + # If "fabfile.py" or "fabfile" dir with "__init__.py" file exists + local f="fabfile" + if [[ -e "$f.py" || (-d "$f" && -e "$f/__init__.py") ]]; then + # Build a list of the available tasks + if $FAB_COMPLETION_CACHE_TASKS; then + # If use cache + if [[ ! -s ${FAB_COMPLETION_CACHED_TASKS_FILENAME} || + $(__fab_fabfile_mtime) -gt $(__fab_chache_mtime) ]]; then + fab --shortlist > ${FAB_COMPLETION_CACHED_TASKS_FILENAME} \ + 2> /dev/null + fi + opts=$(cat ${FAB_COMPLETION_CACHED_TASKS_FILENAME}) + else + # Without cache + opts=$(fab --shortlist 2> /dev/null) + fi + fi + ;; + esac + + # Set possible completions + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) } complete -o default -o nospace -F __fab_completion fab diff --git a/completion/available/git_flow.completion.bash b/completion/available/git_flow.completion.bash index 7bfc9ef42c..a715cca4d9 100644 --- a/completion/available/git_flow.completion.bash +++ b/completion/available/git_flow.completion.bash @@ -45,8 +45,7 @@ # # Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/) -_git_flow () -{ +_git_flow() { local subcommands="init feature release hotfix" local subcommand="$(__git_find_subcommand "$subcommands")" if [ -z "$subcommand" ]; then @@ -55,26 +54,25 @@ _git_flow () fi case "$subcommand" in - feature) - __git_flow_feature - return - ;; - release) - __git_flow_release - return - ;; - hotfix) - __git_flow_hotfix - return - ;; - *) - COMPREPLY=() - ;; + feature) + __git_flow_feature + return + ;; + release) + __git_flow_release + return + ;; + hotfix) + __git_flow_hotfix + return + ;; + *) + COMPREPLY=() + ;; esac } -__git_flow_feature () -{ +__git_flow_feature() { local subcommands="list start finish publish track diff rebase checkout pull" local subcommand="$(__git_find_subcommand "$subcommands")" if [ -z "$subcommand" ]; then @@ -83,45 +81,41 @@ __git_flow_feature () fi case "$subcommand" in - pull) - __gitcomp "$(__git_remotes)" - return - ;; - checkout|finish|diff|rebase) - __gitcomp "$(__git_flow_list_features)" - return - ;; - publish) - __gitcomp "$(comm -23 <(__git_flow_list_features) <(__git_flow_list_remote_features))" - return - ;; - track) - __gitcomp "$(__git_flow_list_remote_features)" - return - ;; - *) - COMPREPLY=() - ;; + pull) + __gitcomp "$(__git_remotes)" + return + ;; + checkout | finish | diff | rebase) + __gitcomp "$(__git_flow_list_features)" + return + ;; + publish) + __gitcomp "$(comm -23 <(__git_flow_list_features) <(__git_flow_list_remote_features))" + return + ;; + track) + __gitcomp "$(__git_flow_list_remote_features)" + return + ;; + *) + COMPREPLY=() + ;; esac } -__git_flow_list_features () -{ +__git_flow_list_features() { git flow feature list 2> /dev/null | tr -d ' |*' } -__git_flow_list_remote_features () -{ +__git_flow_list_remote_features() { git branch -r 2> /dev/null | grep "origin/$(__git_flow_feature_prefix)" | awk '{ sub(/^origin\/$(__git_flow_feature_prefix)/, "", $1); print }' } -__git_flow_feature_prefix () -{ +__git_flow_feature_prefix() { git config gitflow.prefix.feature 2> /dev/null || echo "feature/" } -__git_flow_release () -{ +__git_flow_release() { local subcommands="list start finish" local subcommand="$(__git_find_subcommand "$subcommands")" if [ -z "$subcommand" ]; then @@ -130,24 +124,22 @@ __git_flow_release () fi case "$subcommand" in - finish) - __gitcomp "$(__git_flow_list_releases)" - return - ;; - *) - COMPREPLY=() - ;; + finish) + __gitcomp "$(__git_flow_list_releases)" + return + ;; + *) + COMPREPLY=() + ;; esac } -__git_flow_list_releases () -{ +__git_flow_list_releases() { git flow release list 2> /dev/null } -__git_flow_hotfix () -{ +__git_flow_hotfix() { local subcommands="list start finish" local subcommand="$(__git_find_subcommand "$subcommands")" if [ -z "$subcommand" ]; then @@ -156,23 +148,21 @@ __git_flow_hotfix () fi case "$subcommand" in - finish) - __gitcomp "$(__git_flow_list_hotfixes)" - return - ;; - *) - COMPREPLY=() - ;; + finish) + __gitcomp "$(__git_flow_list_hotfixes)" + return + ;; + *) + COMPREPLY=() + ;; esac } -__git_flow_list_hotfixes () -{ +__git_flow_list_hotfixes() { git flow hotfix list 2> /dev/null } # temporarily wrap __git_find_on_cmdline() for backwards compatibility -if ! _command_exists __git_find_subcommand -then +if ! _command_exists __git_find_subcommand; then alias __git_find_subcommand=__git_find_on_cmdline fi diff --git a/completion/available/git_flow_avh.completion.bash b/completion/available/git_flow_avh.completion.bash index abb51bf806..ce4a7db3e4 100644 --- a/completion/available/git_flow_avh.completion.bash +++ b/completion/available/git_flow_avh.completion.bash @@ -53,8 +53,7 @@ __git_flow_config_file_options=" --local --global --system --file= " -_git_flow () -{ +_git_flow() { local subcommands="init feature release hotfix support help version config finish delete publish rebase" local subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then @@ -63,38 +62,37 @@ _git_flow () fi case "$subcommand" in - init) - __git_flow_init - return - ;; - feature) - __git_flow_feature - return - ;; - release) - __git_flow_release - return - ;; - hotfix) - __git_flow_hotfix - return - ;; - support) - __git_flow_support - return - ;; - config) - __git_flow_config - return - ;; - *) - COMPREPLY=() - ;; + init) + __git_flow_init + return + ;; + feature) + __git_flow_feature + return + ;; + release) + __git_flow_release + return + ;; + hotfix) + __git_flow_hotfix + return + ;; + support) + __git_flow_support + return + ;; + config) + __git_flow_config + return + ;; + *) + COMPREPLY=() + ;; esac } -__git_flow_init () -{ +__git_flow_init() { local subcommands="help" local subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then @@ -102,19 +100,18 @@ __git_flow_init () fi case "$cur" in - --*) - __gitcomp " + --*) + __gitcomp " --nodefaults --defaults --noforce --force $__git_flow_config_file_options " - return - ;; + return + ;; esac } -__git_flow_feature () -{ +__git_flow_feature() { local subcommands="list start finish publish track diff rebase checkout pull help delete" local subcommand="$(__git_find_on_cmdline "$subcommands")" @@ -124,31 +121,31 @@ __git_flow_feature () fi case "$subcommand" in - pull) - __gitcomp_nl "$(__git_remotes)" - return - ;; - checkout) - __gitcomp_nl "$(__git_flow_list_local_branches 'feature')" - return - ;; - delete) - case "$cur" in - --*) - __gitcomp " + pull) + __gitcomp_nl "$(__git_remotes)" + return + ;; + checkout) + __gitcomp_nl "$(__git_flow_list_local_branches 'feature')" + return + ;; + delete) + case "$cur" in + --*) + __gitcomp " --noforce --force --noremote --remote " + return + ;; + esac + __gitcomp_nl "$(__git_flow_list_local_branches 'feature')" return ;; - esac - __gitcomp_nl "$(__git_flow_list_local_branches 'feature')" - return - ;; - finish) - case "$cur" in - --*) - __gitcomp " + finish) + case "$cur" in + --*) + __gitcomp " --nofetch --fetch --norebase --rebase --nopreserve-merges --preserve-merges @@ -159,45 +156,44 @@ __git_flow_feature () --nosquash --squash --no-ff " + return + ;; + esac + __gitcomp_nl "$(__git_flow_list_local_branches 'feature')" return ;; - esac - __gitcomp_nl "$(__git_flow_list_local_branches 'feature')" - return - ;; - diff) - __gitcomp_nl "$(__git_flow_list_local_branches 'feature')" - return - ;; - rebase) - case "$cur" in - --*) - __gitcomp " + diff) + __gitcomp_nl "$(__git_flow_list_local_branches 'feature')" + return + ;; + rebase) + case "$cur" in + --*) + __gitcomp " --nointeractive --interactive --nopreserve-merges --preserve-merges " + return + ;; + esac + __gitcomp_nl "$(__git_flow_list_local_branches 'feature')" return ;; - esac - __gitcomp_nl "$(__git_flow_list_local_branches 'feature')" - return - ;; - publish) - __gitcomp_nl "$(__git_flow_list_branches 'feature')" - return - ;; - track) - __gitcomp_nl "$(__git_flow_list_branches 'feature')" - return - ;; - *) - COMPREPLY=() - ;; + publish) + __gitcomp_nl "$(__git_flow_list_branches 'feature')" + return + ;; + track) + __gitcomp_nl "$(__git_flow_list_branches 'feature')" + return + ;; + *) + COMPREPLY=() + ;; esac } -__git_flow_release () -{ +__git_flow_release() { local subcommands="list start finish track publish help delete" local subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then @@ -206,10 +202,10 @@ __git_flow_release () fi case "$subcommand" in - finish) - case "$cur" in - --*) - __gitcomp " + finish) + case "$cur" in + --*) + __gitcomp " --nofetch --fetch --sign --signingkey @@ -224,66 +220,65 @@ __git_flow_release () --nonobackmerge --nobackmerge --nosquash --squash " + return + ;; + esac + __gitcomp_nl "$(__git_flow_list_local_branches 'release')" return ;; - esac - __gitcomp_nl "$(__git_flow_list_local_branches 'release')" - return - ;; - rebase) - case "$cur" in - --*) - __gitcomp " + rebase) + case "$cur" in + --*) + __gitcomp " --nointeractive --interactive --nopreserve-merges --preserve-merges " + return + ;; + esac + __gitcomp_nl "$(__git_flow_list_local_branches 'release')" return ;; - esac - __gitcomp_nl "$(__git_flow_list_local_branches 'release')" - return - ;; - delete) - case "$cur" in - --*) - __gitcomp " + delete) + case "$cur" in + --*) + __gitcomp " --noforce --force --noremote --remote " + return + ;; + esac + __gitcomp_nl "$(__git_flow_list_local_branches 'release')" return ;; - esac - __gitcomp_nl "$(__git_flow_list_local_branches 'release')" - return - ;; - publish) - __gitcomp_nl "$(__git_flow_list_branches 'release')" - return - ;; - track) - __gitcomp_nl "$(__git_flow_list_branches 'release')" - return - ;; - start) - case "$cur" in - --*) - __gitcomp " + publish) + __gitcomp_nl "$(__git_flow_list_branches 'release')" + return + ;; + track) + __gitcomp_nl "$(__git_flow_list_branches 'release')" + return + ;; + start) + case "$cur" in + --*) + __gitcomp " --nofetch --fetch " + return + ;; + esac return ;; - esac - return - ;; - *) - COMPREPLY=() - ;; + *) + COMPREPLY=() + ;; esac } -__git_flow_hotfix () -{ +__git_flow_hotfix() { local subcommands="list start finish track publish help delete" local subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then @@ -292,10 +287,10 @@ __git_flow_hotfix () fi case "$subcommand" in - finish) - case "$cur" in - --*) - __gitcomp " + finish) + case "$cur" in + --*) + __gitcomp " --nofetch --fetch --sign --signingkey @@ -309,65 +304,64 @@ __git_flow_hotfix () --notag --tag --nonobackmerge --nobackmerge " + return + ;; + esac + __gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')" return ;; - esac - __gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')" - return - ;; - rebase) - case "$cur" in - --*) - __gitcomp " + rebase) + case "$cur" in + --*) + __gitcomp " --nointeractive --interactive --nopreserve-merges --preserve-merges " + return + ;; + esac + __gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')" return ;; - esac - __gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')" - return - ;; - delete) - case "$cur" in - --*) - __gitcomp " + delete) + case "$cur" in + --*) + __gitcomp " --noforce --force --noremote --remote " + return + ;; + esac + __gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')" return ;; - esac - __gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')" - return - ;; - publish) - __gitcomp_nl "$(__git_flow_list_branches 'hotfix')" - return - ;; - track) - __gitcomp_nl "$(__git_flow_list_branches 'hotfix')" - return - ;; - start) - case "$cur" in - --*) - __gitcomp " + publish) + __gitcomp_nl "$(__git_flow_list_branches 'hotfix')" + return + ;; + track) + __gitcomp_nl "$(__git_flow_list_branches 'hotfix')" + return + ;; + start) + case "$cur" in + --*) + __gitcomp " --nofetch --fetch " + return + ;; + esac return ;; - esac - return - ;; - *) - COMPREPLY=() - ;; + *) + COMPREPLY=() + ;; esac } -__git_flow_support () -{ +__git_flow_support() { local subcommands="list start help" local subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then @@ -376,38 +370,37 @@ __git_flow_support () fi case "$subcommand" in - start) - case "$cur" in - --*) - __gitcomp " + start) + case "$cur" in + --*) + __gitcomp " --nofetch --fetch " + return + ;; + esac return ;; - esac - return - ;; - rebase) - case "$cur" in - --*) - __gitcomp " + rebase) + case "$cur" in + --*) + __gitcomp " --nointeractive --interactive --nopreserve-merges --preserve-merges " + return + ;; + esac + __gitcomp_nl "$(__git_flow_list_local_branches 'support')" return ;; - esac - __gitcomp_nl "$(__git_flow_list_local_branches 'support')" - return - ;; - *) - COMPREPLY=() - ;; + *) + COMPREPLY=() + ;; esac } -__git_flow_config () -{ +__git_flow_config() { local subcommands="list set base" local subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then @@ -416,56 +409,54 @@ __git_flow_config () fi case "$subcommand" in - set) - case "$cur" in - --*) - __gitcomp " + set) + case "$cur" in + --*) + __gitcomp " $__git_flow_config_file_options " - return - ;; - esac - __gitcomp " + return + ;; + esac + __gitcomp " master develop feature hotfix release support versiontagprefix " - return - ;; - base) - case "$cur" in - --*) - __gitcomp " + return + ;; + base) + case "$cur" in + --*) + __gitcomp " set get " + return + ;; + esac + __gitcomp_nl "$(__git_flow_list_local_branches)" return ;; - esac - __gitcomp_nl "$(__git_flow_list_local_branches)" - return - ;; - *) - COMPREPLY=() - ;; + *) + COMPREPLY=() + ;; esac } -__git_flow_prefix () -{ +__git_flow_prefix() { case "$1" in - feature|release|hotfix|support) - git config "gitflow.prefix.$1" 2> /dev/null || echo "$1/" - return - ;; + feature | release | hotfix | support) + git config "gitflow.prefix.$1" 2> /dev/null || echo "$1/" + return + ;; esac } -__git_flow_list_local_branches () -{ +__git_flow_list_local_branches() { if [ -n "$1" ]; then local prefix="$(__git_flow_prefix $1)" - git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix | \ - while read -r entry; do + git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix \ + | while read -r entry; do eval "$entry" ref="${ref#$prefix}" echo "$ref" @@ -476,25 +467,23 @@ __git_flow_list_local_branches () fi } -__git_flow_list_remote_branches () -{ +__git_flow_list_remote_branches() { local prefix="$(__git_flow_prefix $1)" local origin="$(git config gitflow.origin 2> /dev/null || echo "origin")" - git for-each-ref --shell --format='%(refname:short)' refs/remotes/$origin/$prefix | \ - while read -r entry; do - eval "$entry" - ref="${ref##$prefix}" - echo "$ref" - done | sort + git for-each-ref --shell --format='%(refname:short)' refs/remotes/$origin/$prefix \ + | while read -r entry; do + eval "$entry" + ref="${ref##$prefix}" + echo "$ref" + done | sort } -__git_flow_list_branches () -{ +__git_flow_list_branches() { local origin="$(git config gitflow.origin 2> /dev/null || echo "origin")" if [ -n "$1" ]; then local prefix="$(__git_flow_prefix $1)" - git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix refs/remotes/$origin/$prefix | \ - while read -r entry; do + git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix refs/remotes/$origin/$prefix \ + | while read -r entry; do eval "$entry" ref="${ref##$prefix}" echo "$ref" @@ -505,7 +494,6 @@ __git_flow_list_branches () } # alias __git_find_on_cmdline for backwards compatibility -if ! _command_exists __git_find_on_cmdline -then +if ! _command_exists __git_find_on_cmdline; then alias __git_find_on_cmdline=__git_find_subcommand fi diff --git a/completion/available/gradle.completion.bash b/completion/available/gradle.completion.bash index ef9677c6de..cedf15dc71 100644 --- a/completion/available/gradle.completion.bash +++ b/completion/available/gradle.completion.bash @@ -25,56 +25,56 @@ COMP_WORDBREAKS=$(echo "$COMP_WORDBREAKS" | sed -e 's/://g') function __gradle-set-project-root-dir() { - project_root_dir="$(_bash-it-find-in-ancestor "settings.gradle" "gradlew")" - return "$?" + project_root_dir="$(_bash-it-find-in-ancestor "settings.gradle" "gradlew")" + return "$?" } __gradle-init-cache-dir() { - cache_dir="$HOME/.gradle/completion" - mkdir -p $cache_dir + cache_dir="$HOME/.gradle/completion" + mkdir -p $cache_dir } __gradle-set-build-file() { - # Look for default build script in the settings file (settings.gradle by default) - # Otherwise, default is the file 'build.gradle' in the current directory. - gradle_build_file="$project_root_dir/build.gradle" - if [[ -f "$project_root_dir/settings.gradle" ]]; then - local build_file_name=$(grep "^rootProject\.buildFileName" "$project_root_dir/settings.gradle" | \ - sed -n -e "s/rootProject\.buildFileName = [\'\"]\(.*\)[\'\"]/\1/p") - gradle_build_file="$project_root_dir/${build_file_name:-build.gradle}" - fi + # Look for default build script in the settings file (settings.gradle by default) + # Otherwise, default is the file 'build.gradle' in the current directory. + gradle_build_file="$project_root_dir/build.gradle" + if [[ -f "$project_root_dir/settings.gradle" ]]; then + local build_file_name=$(grep "^rootProject\.buildFileName" "$project_root_dir/settings.gradle" \ + | sed -n -e "s/rootProject\.buildFileName = [\'\"]\(.*\)[\'\"]/\1/p") + gradle_build_file="$project_root_dir/${build_file_name:-build.gradle}" + fi } __gradle-set-cache-name() { - # Cache name is constructed from the absolute path of the build file. - cache_name=$(echo $gradle_build_file | sed -e 's/\//_/g') + # Cache name is constructed from the absolute path of the build file. + cache_name=$(echo $gradle_build_file | sed -e 's/\//_/g') } __gradle-set-files-checksum() { - # Cache MD5 sum of all Gradle scripts and modified timestamps - if _command_exists md5; then - gradle_files_checksum=$(md5 -q -s "$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null)") - elif _command_exists md5sum; then - gradle_files_checksum=$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null | md5sum | awk '{print $1}') - else - echo "Cannot generate completions as neither md5 nor md5sum exist on \$PATH" - fi + # Cache MD5 sum of all Gradle scripts and modified timestamps + if _command_exists md5; then + gradle_files_checksum=$(md5 -q -s "$(cat "$cache_dir/$cache_name" | xargs ls -o 2> /dev/null)") + elif _command_exists md5sum; then + gradle_files_checksum=$(cat "$cache_dir/$cache_name" | xargs ls -o 2> /dev/null | md5sum | awk '{print $1}') + else + echo "Cannot generate completions as neither md5 nor md5sum exist on \$PATH" + fi } __gradle-generate-script-cache() { - # Invalidate cache after 3 weeks by default - local cache_ttl_mins=${GRADLE_CACHE_TTL_MINUTES:-30240} - local script_exclude_pattern=${GRADLE_COMPLETION_EXCLUDE_PATTERN:-"/(build|integTest|out)/"} - - if [[ ! $(find $cache_dir/$cache_name -mmin -$cache_ttl_mins 2>/dev/null) ]]; then - # Cache all Gradle scripts - local gradle_build_scripts=$(find $project_root_dir -type f -name "*.gradle" -o -name "*.gradle.kts" 2>/dev/null | grep -E -v "$script_exclude_pattern") - printf "%s\n" "${gradle_build_scripts[@]}" > $cache_dir/$cache_name - fi + # Invalidate cache after 3 weeks by default + local cache_ttl_mins=${GRADLE_CACHE_TTL_MINUTES:-30240} + local script_exclude_pattern=${GRADLE_COMPLETION_EXCLUDE_PATTERN:-"/(build|integTest|out)/"} + + if [[ ! $(find $cache_dir/$cache_name -mmin -$cache_ttl_mins 2> /dev/null) ]]; then + # Cache all Gradle scripts + local gradle_build_scripts=$(find $project_root_dir -type f -name "*.gradle" -o -name "*.gradle.kts" 2> /dev/null | grep -E -v "$script_exclude_pattern") + printf "%s\n" "${gradle_build_scripts[@]}" > $cache_dir/$cache_name + fi } __gradle-long-options() { - local args="--build-cache - Enables the Gradle build cache + local args="--build-cache - Enables the Gradle build cache --build-file - Specifies the build file --configure-on-demand - Only relevant projects are configured --console - Type of console output to generate (plain auto rich) @@ -115,11 +115,11 @@ __gradle-long-options() { --system-prop - Set a system property --version - Prints Gradle version info --warn - Log warnings and errors only" - COMPREPLY=( $(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}") ) + COMPREPLY=($(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}")) } __gradle-properties() { - local args="-Dorg.gradle.cache.reserved.mb= - Reserve Gradle Daemon memory for operations + local args="-Dorg.gradle.cache.reserved.mb= - Reserve Gradle Daemon memory for operations -Dorg.gradle.caching= - Set true to enable Gradle build cache -Dorg.gradle.daemon.debug= - Set true to debug Gradle Daemon -Dorg.gradle.daemon.idletimeout= - Kill Gradle Daemon after # idle millis @@ -130,12 +130,12 @@ __gradle-properties() { -Dorg.gradle.parallel= - Set true to enable parallel project builds (incubating) -Dorg.gradle.parallel.intra= - Set true to enable intra-project parallel builds (incubating) -Dorg.gradle.workers.max= - Set the number of workers Gradle is allowed to use" - COMPREPLY=( $(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}") ) - return 0 + COMPREPLY=($(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}")) + return 0 } __gradle-short-options() { - local args="-? - Shows a help message + local args="-? - Shows a help message -a - Do not rebuild project dependencies -b - Specifies the build file -c - Specifies the settings file @@ -156,132 +156,132 @@ __gradle-short-options() { -I - Specifies an initialization script -P - Sets a project property of the root project -S - Print out the full (very verbose) stacktrace" - COMPREPLY=( $(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}") ) + COMPREPLY=($(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}")) } __gradle-notify-tasks-cache-build() { - # Notify user of cache rebuild - echo -e " (Building completion cache. Please wait)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\c" - __gradle-generate-tasks-cache - # Remove "please wait" message by writing a bunch of spaces then moving back to the left - echo -e " \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\c" + # Notify user of cache rebuild + echo -e " (Building completion cache. Please wait)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\c" + __gradle-generate-tasks-cache + # Remove "please wait" message by writing a bunch of spaces then moving back to the left + echo -e " \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\c" } __gradle-generate-tasks-cache() { - __gradle-set-files-checksum - - # Use Gradle wrapper when it exists. - local gradle_cmd="gradle" - if [[ -x "$project_root_dir/gradlew" ]]; then - gradle_cmd="$project_root_dir/gradlew" - fi - - # Run gradle to retrieve possible tasks and cache. - # Reuse Gradle Daemon if IDLE but don't start a new one. - local gradle_tasks_output - if [[ ! -z "$($gradle_cmd --status 2>/dev/null | grep IDLE)" ]]; then - gradle_tasks_output="$($gradle_cmd -b $gradle_build_file --daemon -q tasks --all)" - else - gradle_tasks_output="$($gradle_cmd -b $gradle_build_file --no-daemon -q tasks --all)" - fi - local output_line - local task_description - local -a gradle_all_tasks=() - local -a root_tasks=() - local -a subproject_tasks=() - for output_line in $gradle_tasks_output; do - if [[ $output_line =~ ^([[:lower:]][[:alnum:][:punct:]]*)([[:space:]]-[[:space:]]([[:print:]]*))? ]]; then - task_name="${BASH_REMATCH[1]}" - task_description="${BASH_REMATCH[3]}" - gradle_all_tasks+=( "$task_name - $task_description" ) - # Completion for subproject tasks with ':' prefix - if [[ $task_name =~ ^([[:alnum:][:punct:]]+):([[:alnum:]]+) ]]; then - gradle_all_tasks+=( ":$task_name - $task_description" ) - subproject_tasks+=( "${BASH_REMATCH[2]}" ) - else - root_tasks+=( "$task_name" ) - fi - fi - done - - # subproject tasks can be referenced implicitly from root project - if [[ $GRADLE_COMPLETION_UNQUALIFIED_TASKS == "true" ]]; then - local -a implicit_tasks=() - implicit_tasks=( $(comm -23 <(printf "%s\n" "${subproject_tasks[@]}" | sort) <(printf "%s\n" "${root_tasks[@]}" | sort)) ) - for task in $(printf "%s\n" "${implicit_tasks[@]}"); do - gradle_all_tasks+=( $task ) - done - fi - - printf "%s\n" "${gradle_all_tasks[@]}" > $cache_dir/$gradle_files_checksum - echo $gradle_files_checksum > $cache_dir/$cache_name.md5 + __gradle-set-files-checksum + + # Use Gradle wrapper when it exists. + local gradle_cmd="gradle" + if [[ -x "$project_root_dir/gradlew" ]]; then + gradle_cmd="$project_root_dir/gradlew" + fi + + # Run gradle to retrieve possible tasks and cache. + # Reuse Gradle Daemon if IDLE but don't start a new one. + local gradle_tasks_output + if [[ ! -z "$($gradle_cmd --status 2> /dev/null | grep IDLE)" ]]; then + gradle_tasks_output="$($gradle_cmd -b $gradle_build_file --daemon -q tasks --all)" + else + gradle_tasks_output="$($gradle_cmd -b $gradle_build_file --no-daemon -q tasks --all)" + fi + local output_line + local task_description + local -a gradle_all_tasks=() + local -a root_tasks=() + local -a subproject_tasks=() + for output_line in $gradle_tasks_output; do + if [[ $output_line =~ ^([[:lower:]][[:alnum:][:punct:]]*)([[:space:]]-[[:space:]]([[:print:]]*))? ]]; then + task_name="${BASH_REMATCH[1]}" + task_description="${BASH_REMATCH[3]}" + gradle_all_tasks+=("$task_name - $task_description") + # Completion for subproject tasks with ':' prefix + if [[ $task_name =~ ^([[:alnum:][:punct:]]+):([[:alnum:]]+) ]]; then + gradle_all_tasks+=(":$task_name - $task_description") + subproject_tasks+=("${BASH_REMATCH[2]}") + else + root_tasks+=("$task_name") + fi + fi + done + + # subproject tasks can be referenced implicitly from root project + if [[ $GRADLE_COMPLETION_UNQUALIFIED_TASKS == "true" ]]; then + local -a implicit_tasks=() + implicit_tasks=($(comm -23 <(printf "%s\n" "${subproject_tasks[@]}" | sort) <(printf "%s\n" "${root_tasks[@]}" | sort))) + for task in $(printf "%s\n" "${implicit_tasks[@]}"); do + gradle_all_tasks+=($task) + done + fi + + printf "%s\n" "${gradle_all_tasks[@]}" > $cache_dir/$gradle_files_checksum + echo $gradle_files_checksum > $cache_dir/$cache_name.md5 } __gradle-completion-init() { - local cache_dir cache_name gradle_build_file gradle_files_checksum project_root_dir + local cache_dir cache_name gradle_build_file gradle_files_checksum project_root_dir - local OLDIFS="$IFS" - local IFS=$'\n' + local OLDIFS="$IFS" + local IFS=$'\n' - __gradle-init-cache-dir - __gradle-set-project-root-dir - __gradle-set-build-file - if [[ -f $gradle_build_file ]]; then - __gradle-set-cache-name - __gradle-generate-script-cache - __gradle-set-files-checksum - __gradle-notify-tasks-cache-build - fi + __gradle-init-cache-dir + __gradle-set-project-root-dir + __gradle-set-build-file + if [[ -f $gradle_build_file ]]; then + __gradle-set-cache-name + __gradle-generate-script-cache + __gradle-set-files-checksum + __gradle-notify-tasks-cache-build + fi - IFS="$OLDIFS" + IFS="$OLDIFS" - return 0 + return 0 } _gradle() { - local cache_dir cache_name gradle_build_file gradle_files_checksum project_root_dir - local cur=${COMP_WORDS[COMP_CWORD]} - # Set bash internal field separator to '\n' - # This allows us to provide descriptions for options and tasks - local OLDIFS="$IFS" - local IFS=$'\n' - - if [[ ${cur} == --* ]]; then - __gradle-long-options - elif [[ ${cur} == -D* ]]; then - __gradle-properties - elif [[ ${cur} == -* ]]; then - __gradle-short-options - else - __gradle-init-cache-dir - __gradle-set-project-root-dir - __gradle-set-build-file - if [[ -f $gradle_build_file ]]; then - __gradle-set-cache-name - __gradle-generate-script-cache - __gradle-set-files-checksum - - # The cache key is md5 sum of all gradle scripts, so it's valid if it exists. - if [[ -f $cache_dir/$cache_name.md5 ]]; then - local cached_checksum="$(cat $cache_dir/$cache_name.md5)" - local -a cached_tasks - if [[ -z $cur ]]; then - cached_tasks=( $(cat $cache_dir/$cached_checksum) ) - else - cached_tasks=( $(grep "^$cur" $cache_dir/$cached_checksum) ) - fi - COMPREPLY=( $(compgen -W "${cached_tasks[*]}" -- "$cur") ) - else - __gradle-notify-tasks-cache-build - fi - - # Regenerate tasks cache in the background - if [[ $gradle_files_checksum != "$(cat $cache_dir/$cache_name.md5)" || ! -f $cache_dir/$gradle_files_checksum ]]; then - $(__gradle-generate-tasks-cache 1>&2 2>/dev/null &) - fi - else - # Default tasks available outside Gradle projects - local args="buildEnvironment - Displays all buildscript dependencies declared in root project. + local cache_dir cache_name gradle_build_file gradle_files_checksum project_root_dir + local cur=${COMP_WORDS[COMP_CWORD]} + # Set bash internal field separator to '\n' + # This allows us to provide descriptions for options and tasks + local OLDIFS="$IFS" + local IFS=$'\n' + + if [[ ${cur} == --* ]]; then + __gradle-long-options + elif [[ ${cur} == -D* ]]; then + __gradle-properties + elif [[ ${cur} == -* ]]; then + __gradle-short-options + else + __gradle-init-cache-dir + __gradle-set-project-root-dir + __gradle-set-build-file + if [[ -f $gradle_build_file ]]; then + __gradle-set-cache-name + __gradle-generate-script-cache + __gradle-set-files-checksum + + # The cache key is md5 sum of all gradle scripts, so it's valid if it exists. + if [[ -f $cache_dir/$cache_name.md5 ]]; then + local cached_checksum="$(cat $cache_dir/$cache_name.md5)" + local -a cached_tasks + if [[ -z $cur ]]; then + cached_tasks=($(cat $cache_dir/$cached_checksum)) + else + cached_tasks=($(grep "^$cur" $cache_dir/$cached_checksum)) + fi + COMPREPLY=($(compgen -W "${cached_tasks[*]}" -- "$cur")) + else + __gradle-notify-tasks-cache-build + fi + + # Regenerate tasks cache in the background + if [[ $gradle_files_checksum != "$(cat $cache_dir/$cache_name.md5)" || ! -f $cache_dir/$gradle_files_checksum ]]; then + $(__gradle-generate-tasks-cache 1>&2 2> /dev/null &) + fi + else + # Default tasks available outside Gradle projects + local args="buildEnvironment - Displays all buildscript dependencies declared in root project. components - Displays the components produced by root project. dependencies - Displays all dependencies declared in root project. dependencyInsight - Displays the insight into a specific dependency in root project. @@ -293,18 +293,18 @@ projects - Displays the sub-projects of root project. properties - Displays the properties of root project. tasks - Displays the tasks runnable from root project. wrapper - Generates Gradle wrapper files." - COMPREPLY=( $(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}") ) - fi - fi + COMPREPLY=($(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}")) + fi + fi - IFS="$OLDIFS" + IFS="$OLDIFS" - # Remove description ("[:space:]" and after) if only one possibility - if [[ ${#COMPREPLY[*]} -eq 1 ]]; then - COMPREPLY=( ${COMPREPLY[0]%% *} ) - fi + # Remove description ("[:space:]" and after) if only one possibility + if [[ ${#COMPREPLY[*]} -eq 1 ]]; then + COMPREPLY=(${COMPREPLY[0]%% *}) + fi - return 0 + return 0 } complete -F _gradle gradle complete -F _gradle gradle.bat @@ -313,6 +313,6 @@ complete -F _gradle gradlew.bat complete -F _gradle ./gradlew complete -F _gradle ./gradlew.bat -if hash gw 2>/dev/null || alias gw >/dev/null 2>&1; then - complete -F _gradle gw +if hash gw 2> /dev/null || alias gw > /dev/null 2>&1; then + complete -F _gradle gw fi diff --git a/completion/available/grunt.completion.bash b/completion/available/grunt.completion.bash index e655c4eea6..41399e72bf 100644 --- a/completion/available/grunt.completion.bash +++ b/completion/available/grunt.completion.bash @@ -42,34 +42,34 @@ # Search the current directory and all parent directories for a gruntfile. function _grunt_gruntfile() { - local curpath="$PWD" - while [[ "$curpath" ]]; do - for gruntfile in "$curpath/"{G,g}runtfile.{js,coffee}; do - if [[ -e "$gruntfile" ]]; then - echo "$gruntfile" - return - fi - done - curpath="${curpath%/*}" - done - return 1 + local curpath="$PWD" + while [[ "$curpath" ]]; do + for gruntfile in "$curpath/"{G,g}runtfile.{js,coffee}; do + if [[ -e "$gruntfile" ]]; then + echo "$gruntfile" + return + fi + done + curpath="${curpath%/*}" + done + return 1 } # Enable bash autocompletion. function _grunt_completions() { - # The currently-being-completed word. - local cur="${COMP_WORDS[COMP_CWORD]}" - # The current gruntfile, if it exists. - local gruntfile="$(_grunt_gruntfile)" - # The current grunt version, available tasks, options, etc. - local gruntinfo="$(grunt --version --verbose 2>/dev/null)" - # Options and tasks. - local opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')" - local compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')" - # Only add -- or - options if the user has started typing - - [[ "$cur" == -* ]] && compls="$compls $opts" - # Tell complete what stuff to show. - COMPREPLY=($(compgen -W "$compls" -- "$cur")) + # The currently-being-completed word. + local cur="${COMP_WORDS[COMP_CWORD]}" + # The current gruntfile, if it exists. + local gruntfile="$(_grunt_gruntfile)" + # The current grunt version, available tasks, options, etc. + local gruntinfo="$(grunt --version --verbose 2> /dev/null)" + # Options and tasks. + local opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')" + local compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')" + # Only add -- or - options if the user has started typing - + [[ "$cur" == -* ]] && compls="$compls $opts" + # Tell complete what stuff to show. + COMPREPLY=($(compgen -W "$compls" -- "$cur")) } complete -o default -F _grunt_completions grunt diff --git a/completion/available/gulp.completion.bash b/completion/available/gulp.completion.bash index 91e287645a..63a2fa3d66 100644 --- a/completion/available/gulp.completion.bash +++ b/completion/available/gulp.completion.bash @@ -40,11 +40,11 @@ # eval "$(gulp --completion=bash)" # Enable bash autocompletion. function _gulp_completions() { -# The currently-being-completed word. -local cur="${COMP_WORDS[COMP_CWORD]}" -#Grab tasks -local compls=$(gulp --tasks-simple) -# Tell complete what stuff to show. -COMPREPLY=($(compgen -W "$compls" -- "$cur")) + # The currently-being-completed word. + local cur="${COMP_WORDS[COMP_CWORD]}" + #Grab tasks + local compls=$(gulp --tasks-simple) + # Tell complete what stuff to show. + COMPREPLY=($(compgen -W "$compls" -- "$cur")) } complete -o default -F _gulp_completions gulp diff --git a/completion/available/hub.completion.bash b/completion/available/hub.completion.bash index 67a5e29b1a..b607fdd1d7 100644 --- a/completion/available/hub.completion.bash +++ b/completion/available/hub.completion.bash @@ -24,385 +24,385 @@ # If there is no git tab completion, but we have the _completion loader try to load it if ! _is_function _git && _is_function _completion_loader; then - _completion_loader git + _completion_loader git fi # Check that git tab completion is available and we haven't already set up completion if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then - # Duplicate and rename the 'list_all_commands' function - eval "$(declare -f __git_list_all_commands | \ - sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')" + # Duplicate and rename the 'list_all_commands' function + eval "$(declare -f __git_list_all_commands \ + | sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')" - # Wrap the 'list_all_commands' function with extra hub commands - __git_list_all_commands() { - cat <<-EOF -alias -pull-request -pr -issue -release -fork -create -delete -browse -compare -ci-status -sync -EOF - __git_list_all_commands_without_hub - } + # Wrap the 'list_all_commands' function with extra hub commands + __git_list_all_commands() { + cat <<- EOF + alias + pull-request + pr + issue + release + fork + create + delete + browse + compare + ci-status + sync + EOF + __git_list_all_commands_without_hub + } - # Ensure cached commands are cleared - __git_all_commands="" + # Ensure cached commands are cleared + __git_all_commands="" - ########################## - # hub command completions - ########################## + ########################## + # hub command completions + ########################## - # hub alias [-s] [SHELL] - _git_alias() { - local i c=2 s=-s sh shells="bash zsh sh ksh csh fish" - while [ $c -lt $cword ]; do - i="${words[c]}" - case "$i" in - -s) - unset s - ;; - *) - for sh in $shells; do - if [ "$sh" = "$i" ]; then - unset shells - break - fi - done - ;; - esac - ((c++)) - done - __gitcomp "$s $shells" - } + # hub alias [-s] [SHELL] + _git_alias() { + local i c=2 s=-s sh shells="bash zsh sh ksh csh fish" + while [ $c -lt $cword ]; do + i="${words[c]}" + case "$i" in + -s) + unset s + ;; + *) + for sh in $shells; do + if [ "$sh" = "$i" ]; then + unset shells + break + fi + done + ;; + esac + ((c++)) + done + __gitcomp "$s $shells" + } - # hub browse [-u] [--|[USER/]REPOSITORY] [SUBPAGE] - _git_browse() { - local i c=2 u=-u repo subpage - local subpages_="commits issues tree wiki pulls branches stargazers + # hub browse [-u] [--|[USER/]REPOSITORY] [SUBPAGE] + _git_browse() { + local i c=2 u=-u repo subpage + local subpages_="commits issues tree wiki pulls branches stargazers contributors network network/ graphs graphs/" - local subpages_network="members" - local subpages_graphs="commit-activity code-frequency punch-card" - while [ $c -lt $cword ]; do - i="${words[c]}" - case "$i" in - -u) - unset u - ;; - *) - if [ -z "$repo" ]; then - repo=$i - else - subpage=$i - fi - ;; - esac - ((c++)) - done - if [ -z "$repo" ]; then - __gitcomp "$u -- $(__hub_github_repos '\p')" - elif [ -z "$subpage" ]; then - case "$cur" in - */*) - local pfx="${cur%/*}" cur_="${cur#*/}" - local subpages_var="subpages_$pfx" - __gitcomp "${!subpages_var}" "$pfx/" "$cur_" - ;; - *) - __gitcomp "$u ${subpages_}" - ;; - esac - else - __gitcomp "$u" - fi - } + local subpages_network="members" + local subpages_graphs="commit-activity code-frequency punch-card" + while [ $c -lt $cword ]; do + i="${words[c]}" + case "$i" in + -u) + unset u + ;; + *) + if [ -z "$repo" ]; then + repo=$i + else + subpage=$i + fi + ;; + esac + ((c++)) + done + if [ -z "$repo" ]; then + __gitcomp "$u -- $(__hub_github_repos '\p')" + elif [ -z "$subpage" ]; then + case "$cur" in + */*) + local pfx="${cur%/*}" cur_="${cur#*/}" + local subpages_var="subpages_$pfx" + __gitcomp "${!subpages_var}" "$pfx/" "$cur_" + ;; + *) + __gitcomp "$u ${subpages_}" + ;; + esac + else + __gitcomp "$u" + fi + } - # hub compare [-u] [USER[/REPOSITORY]] [[START...]END] - _git_compare() { - local i c=$((cword - 1)) u=-u user remote owner repo arg_repo rev - while [ $c -gt 1 ]; do - i="${words[c]}" - case "$i" in - -u) - unset u - ;; - *) - if [ -z "$rev" ]; then - # Even though the logic below is able to complete both user/repo - # and revision in the right place, when there is only one argument - # (other than -u) in the command, that argument will be taken as - # revision. For example: - # $ hub compare -u upstream - # > https://github.com/USER/REPO/compare/upstream - if __hub_github_repos '\p' | grep -Eqx "^$i(/[^/]+)?"; then - arg_repo=$i - else - rev=$i - fi - elif [ -z "$arg_repo" ]; then - arg_repo=$i - fi - ;; - esac - ((c--)) - done + # hub compare [-u] [USER[/REPOSITORY]] [[START...]END] + _git_compare() { + local i c=$((cword - 1)) u=-u user remote owner repo arg_repo rev + while [ $c -gt 1 ]; do + i="${words[c]}" + case "$i" in + -u) + unset u + ;; + *) + if [ -z "$rev" ]; then + # Even though the logic below is able to complete both user/repo + # and revision in the right place, when there is only one argument + # (other than -u) in the command, that argument will be taken as + # revision. For example: + # $ hub compare -u upstream + # > https://github.com/USER/REPO/compare/upstream + if __hub_github_repos '\p' | grep -Eqx "^$i(/[^/]+)?"; then + arg_repo=$i + else + rev=$i + fi + elif [ -z "$arg_repo" ]; then + arg_repo=$i + fi + ;; + esac + ((c--)) + done - # Here we want to find out the git remote name of user/repo, in order to - # generate an appropriate revision list - if [ -z "$arg_repo" ]; then - user=$(__hub_github_user) - if [ -z "$user" ]; then - for i in $(__hub_github_repos); do - remote=${i%%:*} - repo=${i#*:} - if [ "$remote" = origin ]; then - break - fi - done - else - for i in $(__hub_github_repos); do - remote=${i%%:*} - repo=${i#*:} - owner=${repo%%/*} - if [ "$user" = "$owner" ]; then - break - fi - done - fi - else - for i in $(__hub_github_repos); do - remote=${i%%:*} - repo=${i#*:} - owner=${repo%%/*} - case "$arg_repo" in - "$repo"|"$owner") - break - ;; - esac - done - fi + # Here we want to find out the git remote name of user/repo, in order to + # generate an appropriate revision list + if [ -z "$arg_repo" ]; then + user=$(__hub_github_user) + if [ -z "$user" ]; then + for i in $(__hub_github_repos); do + remote=${i%%:*} + repo=${i#*:} + if [ "$remote" = origin ]; then + break + fi + done + else + for i in $(__hub_github_repos); do + remote=${i%%:*} + repo=${i#*:} + owner=${repo%%/*} + if [ "$user" = "$owner" ]; then + break + fi + done + fi + else + for i in $(__hub_github_repos); do + remote=${i%%:*} + repo=${i#*:} + owner=${repo%%/*} + case "$arg_repo" in + "$repo" | "$owner") + break + ;; + esac + done + fi - local pfx cur_="$cur" - case "$cur_" in - *..*) - pfx="${cur_%%..*}..." - cur_="${cur_##*..}" - __gitcomp_nl "$(__hub_revlist $remote)" "$pfx" "$cur_" - ;; - *) - if [ -z "${arg_repo}${rev}" ]; then - __gitcomp "$u $(__hub_github_repos '\o\n\p') $(__hub_revlist $remote)" - elif [ -z "$rev" ]; then - __gitcomp "$u $(__hub_revlist $remote)" - else - __gitcomp "$u" - fi - ;; - esac - } + local pfx cur_="$cur" + case "$cur_" in + *..*) + pfx="${cur_%%..*}..." + cur_="${cur_##*..}" + __gitcomp_nl "$(__hub_revlist $remote)" "$pfx" "$cur_" + ;; + *) + if [ -z "${arg_repo}${rev}" ]; then + __gitcomp "$u $(__hub_github_repos '\o\n\p') $(__hub_revlist $remote)" + elif [ -z "$rev" ]; then + __gitcomp "$u $(__hub_revlist $remote)" + else + __gitcomp "$u" + fi + ;; + esac + } - # hub create [NAME] [-p] [-d DESCRIPTION] [-h HOMEPAGE] - _git_create() { - local i c=2 name repo flags="-p -d -h" - while [ $c -lt $cword ]; do - i="${words[c]}" - case "$i" in - -d|-h) - ((c++)) - flags=${flags/$i/} - ;; - -p) - flags=${flags/$i/} - ;; - *) - name=$i - ;; - esac - ((c++)) - done - if [ -z "$name" ]; then - repo="$(basename "${PWD}")" - fi - case "$prev" in - -d|-h) - COMPREPLY=() - ;; - -p|*) - __gitcomp "$repo $flags" - ;; - esac - } + # hub create [NAME] [-p] [-d DESCRIPTION] [-h HOMEPAGE] + _git_create() { + local i c=2 name repo flags="-p -d -h" + while [ $c -lt $cword ]; do + i="${words[c]}" + case "$i" in + -d | -h) + ((c++)) + flags=${flags/$i/} + ;; + -p) + flags=${flags/$i/} + ;; + *) + name=$i + ;; + esac + ((c++)) + done + if [ -z "$name" ]; then + repo="$(basename "${PWD}")" + fi + case "$prev" in + -d | -h) + COMPREPLY=() + ;; + -p | *) + __gitcomp "$repo $flags" + ;; + esac + } - # hub fork [--no-remote] [--remote-name REMOTE] [--org ORGANIZATION] - _git_fork() { - local i c=2 flags="--no-remote --remote-name --org" - while [ $c -lt $cword ]; do - i="${words[c]}" - case "$i" in - --org) - ((c++)) - flags=${flags/$i/} - ;; - --remote-name) - ((c++)) - flags=${flags/$i/} - flags=${flags/--no-remote/} - ;; - --no-remote) - flags=${flags/$i/} - flags=${flags/--remote-name/} - ;; - esac - ((c++)) - done - case "$prev" in - --remote-name|--org) - COMPREPLY=() - ;; - *) - __gitcomp "$flags" - ;; - esac - } + # hub fork [--no-remote] [--remote-name REMOTE] [--org ORGANIZATION] + _git_fork() { + local i c=2 flags="--no-remote --remote-name --org" + while [ $c -lt $cword ]; do + i="${words[c]}" + case "$i" in + --org) + ((c++)) + flags=${flags/$i/} + ;; + --remote-name) + ((c++)) + flags=${flags/$i/} + flags=${flags/--no-remote/} + ;; + --no-remote) + flags=${flags/$i/} + flags=${flags/--remote-name/} + ;; + esac + ((c++)) + done + case "$prev" in + --remote-name | --org) + COMPREPLY=() + ;; + *) + __gitcomp "$flags" + ;; + esac + } - # hub pull-request [-f] [-m |-F |-i |] [-b ] [-h ] [-a ] [-M ] [-l ] - _git_pull_request() { - local i c=2 flags="-f -m -F -i -b -h -a -M -l" - while [ $c -lt $cword ]; do - i="${words[c]}" - case "$i" in - -m|-F|-i|-b|-h|-a|-M|-l) - ((c++)) - flags=${flags/$i/} - ;; - -f) - flags=${flags/$i/} - ;; - esac - ((c++)) - done - case "$prev" in - -i) - COMPREPLY=() - ;; - -b|-h|-a|-M|-l) - # (Doesn't seem to need this...) - # Uncomment the following line when 'owner/repo:[TAB]' misbehaved - #_get_comp_words_by_ref -n : cur - __gitcomp_nl "$(__hub_heads)" - # __ltrim_colon_completions "$cur" - ;; - -F) - COMPREPLY=( "$cur"* ) - ;; - -f|*) - __gitcomp "$flags" - ;; - esac - } + # hub pull-request [-f] [-m |-F |-i |] [-b ] [-h ] [-a ] [-M ] [-l ] + _git_pull_request() { + local i c=2 flags="-f -m -F -i -b -h -a -M -l" + while [ $c -lt $cword ]; do + i="${words[c]}" + case "$i" in + -m | -F | -i | -b | -h | -a | -M | -l) + ((c++)) + flags=${flags/$i/} + ;; + -f) + flags=${flags/$i/} + ;; + esac + ((c++)) + done + case "$prev" in + -i) + COMPREPLY=() + ;; + -b | -h | -a | -M | -l) + # (Doesn't seem to need this...) + # Uncomment the following line when 'owner/repo:[TAB]' misbehaved + #_get_comp_words_by_ref -n : cur + __gitcomp_nl "$(__hub_heads)" + # __ltrim_colon_completions "$cur" + ;; + -F) + COMPREPLY=("$cur"*) + ;; + -f | *) + __gitcomp "$flags" + ;; + esac + } - ################### - # Helper functions - ################### + ################### + # Helper functions + ################### - # __hub_github_user [HOST] - # Return $GITHUB_USER or the default github user defined in hub config - # HOST - Host to be looked-up in hub config. Default is "github.com" - __hub_github_user() { - if [ -n "$GITHUB_USER" ]; then - echo $GITHUB_USER - return - fi - local line h k v host=${1:-github.com} config=${HUB_CONFIG:-~/.config/hub} - if [ -f "$config" ]; then - while read line; do - if [ "$line" = "---" ]; then - continue - fi - k=${line%%:*} - v=${line#*:} - if [ -z "$v" ]; then - if [ "$h" = "$host" ]; then - break - fi - h=$k - continue - fi - k=${k#* } - v=${v#* } - if [ "$h" = "$host" ] && [ "$k" = "user" ]; then - echo "$v" - break - fi - done < "$config" - fi - } + # __hub_github_user [HOST] + # Return $GITHUB_USER or the default github user defined in hub config + # HOST - Host to be looked-up in hub config. Default is "github.com" + __hub_github_user() { + if [ -n "$GITHUB_USER" ]; then + echo $GITHUB_USER + return + fi + local line h k v host=${1:-github.com} config=${HUB_CONFIG:-~/.config/hub} + if [ -f "$config" ]; then + while read line; do + if [ "$line" = "---" ]; then + continue + fi + k=${line%%:*} + v=${line#*:} + if [ -z "$v" ]; then + if [ "$h" = "$host" ]; then + break + fi + h=$k + continue + fi + k=${k#* } + v=${v#* } + if [ "$h" = "$host" ] && [ "$k" = "user" ]; then + echo "$v" + break + fi + done < "$config" + fi + } - # __hub_github_repos [FORMAT] - # List all github hosted repository - # FORMAT - Format string contains multiple of these: - # \m remote - # \p owner/repo - # \o owner - # escaped characters (\n, \t ...etc) work - # If omitted, prints all github repos in the format of "remote:owner/repo" - __hub_github_repos() { - local f format=$1 - if [ -z "$(__gitdir)" ]; then - return - fi - if [ -z "$format" ]; then - format='\1:\2' - else - format=${format//\m/\1} - format=${format//\p/\2} - format=${format//\o/\3} - fi - command git config --get-regexp 'remote\.[^.]*\.url' | - grep -E ' ((https?|git)://|git@)github\.com[:/][^:/]+/[^/]+$' | - sed -E 's#^remote\.([^.]+)\.url +.+[:/](([^/]+)/[^.]+)(\.git)?$#'"$format"'#' - } + # __hub_github_repos [FORMAT] + # List all github hosted repository + # FORMAT - Format string contains multiple of these: + # \m remote + # \p owner/repo + # \o owner + # escaped characters (\n, \t ...etc) work + # If omitted, prints all github repos in the format of "remote:owner/repo" + __hub_github_repos() { + local f format=$1 + if [ -z "$(__gitdir)" ]; then + return + fi + if [ -z "$format" ]; then + format='\1:\2' + else + format=${format//\m/\1} + format=${format//\p/\2} + format=${format//\o/\3} + fi + command git config --get-regexp 'remote\.[^.]*\.url' \ + | grep -E ' ((https?|git)://|git@)github\.com[:/][^:/]+/[^/]+$' \ + | sed -E 's#^remote\.([^.]+)\.url +.+[:/](([^/]+)/[^.]+)(\.git)?$#'"$format"'#' + } - # __hub_heads - # List all local "branch", and remote "owner/repo:branch" - __hub_heads() { - local i remote repo branch dir=$(__gitdir) - if [ -d "$dir" ]; then - command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ - "refs/heads/" - for i in $(__hub_github_repos); do - remote=${i%%:*} - repo=${i#*:} - command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ - "refs/remotes/${remote}/" | while read branch; do - echo "${repo}:${branch#${remote}/}" - done - done - fi - } + # __hub_heads + # List all local "branch", and remote "owner/repo:branch" + __hub_heads() { + local i remote repo branch dir=$(__gitdir) + if [ -d "$dir" ]; then + command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ + "refs/heads/" + for i in $(__hub_github_repos); do + remote=${i%%:*} + repo=${i#*:} + command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ + "refs/remotes/${remote}/" | while read branch; do + echo "${repo}:${branch#${remote}/}" + done + done + fi + } - # __hub_revlist [REMOTE] - # List all tags, and branches under REMOTE, without the "remote/" prefix - # REMOTE - Remote name to search branches from. Default is "origin" - __hub_revlist() { - local i remote=${1:-origin} dir=$(__gitdir) - if [ -d "$dir" ]; then - command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ - "refs/remotes/${remote}/" | while read i; do - echo "${i#${remote}/}" - done - command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ - "refs/tags/" - fi - } + # __hub_revlist [REMOTE] + # List all tags, and branches under REMOTE, without the "remote/" prefix + # REMOTE - Remote name to search branches from. Default is "origin" + __hub_revlist() { + local i remote=${1:-origin} dir=$(__gitdir) + if [ -d "$dir" ]; then + command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ + "refs/remotes/${remote}/" | while read i; do + echo "${i#${remote}/}" + done + command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ + "refs/tags/" + fi + } - # Enable completion for hub even when not using the alias - complete -o bashdefault -o default -o nospace -F _git hub 2>/dev/null \ - || complete -o default -o nospace -F _git hub + # Enable completion for hub even when not using the alias + complete -o bashdefault -o default -o nospace -F _git hub 2> /dev/null \ + || complete -o default -o nospace -F _git hub fi diff --git a/completion/available/invoke.completion.bash b/completion/available/invoke.completion.bash index 708596b47e..89449445cd 100644 --- a/completion/available/invoke.completion.bash +++ b/completion/available/invoke.completion.bash @@ -26,27 +26,26 @@ # https://github.com/pyinvoke/invoke/blob/master/completion/bash _complete_invoke() { - local candidates - - # COMP_WORDS contains the entire command string up til now (including - # program name). - # We hand it to Invoke so it can figure out the current context: spit back - # core options, task names, the current task's options, or some combo. - candidates=`invoke --complete -- ${COMP_WORDS[*]}` - - # `compgen -W` takes list of valid options & a partial word & spits back - # possible matches. Necessary for any partial word completions (vs - # completions performed when no partial words are present). - # - # $2 is the current word or token being tabbed on, either empty string or a - # partial word, and thus wants to be compgen'd to arrive at some subset of - # our candidate list which actually matches. - # - # COMPREPLY is the list of valid completions handed back to `complete`. - COMPREPLY=( $(compgen -W "${candidates}" -- $2) ) + local candidates + + # COMP_WORDS contains the entire command string up til now (including + # program name). + # We hand it to Invoke so it can figure out the current context: spit back + # core options, task names, the current task's options, or some combo. + candidates=$(invoke --complete -- ${COMP_WORDS[*]}) + + # `compgen -W` takes list of valid options & a partial word & spits back + # possible matches. Necessary for any partial word completions (vs + # completions performed when no partial words are present). + # + # $2 is the current word or token being tabbed on, either empty string or a + # partial word, and thus wants to be compgen'd to arrive at some subset of + # our candidate list which actually matches. + # + # COMPREPLY is the list of valid completions handed back to `complete`. + COMPREPLY=($(compgen -W "${candidates}" -- $2)) } - # Tell shell builtin to use the above for completing 'inv'/'invoke': # * -F: use given function name to generate completions. # * -o default: when function generates no results, use filenames. diff --git a/completion/available/kind.completion.bash b/completion/available/kind.completion.bash index be12a2d29c..b48f0ef29a 100644 --- a/completion/available/kind.completion.bash +++ b/completion/available/kind.completion.bash @@ -1,5 +1,5 @@ #!/usr/bin/env bash if _command_exists kind; then - eval "$(kind completion bash)" + eval "$(kind completion bash)" fi diff --git a/completion/available/makefile.completion.bash b/completion/available/makefile.completion.bash index 018586cacf..4b36402efc 100644 --- a/completion/available/makefile.completion.bash +++ b/completion/available/makefile.completion.bash @@ -4,32 +4,32 @@ # Loosely adapted from http://stackoverflow.com/a/38415982/1472048 _makecomplete() { - COMPREPLY=() + COMPREPLY=() - # https://www.gnu.org/software/make/manual/html_node/Makefile-Names.html - local files=() - for f in 'GNUmakefile' 'makefile' 'Makefile' ; do - [ -f "$f" ] && files+=("$f") - done + # https://www.gnu.org/software/make/manual/html_node/Makefile-Names.html + local files=() + for f in 'GNUmakefile' 'makefile' 'Makefile'; do + [ -f "$f" ] && files+=("$f") + done - [ "${#files[@]}" -eq 0 ] && return 0 + [ "${#files[@]}" -eq 0 ] && return 0 - # collect all targets - local targets=() - for f in "${files[@]}" ; do - while IFS='' read -r line ; do - targets+=("$line") - done < <(grep -E -o '^[a-zA-Z0-9_-]+:([^=]|$)' "$f" | cut -d':' -f1) - done + # collect all targets + local targets=() + for f in "${files[@]}"; do + while IFS='' read -r line; do + targets+=("$line") + done < <(grep -E -o '^[a-zA-Z0-9_-]+:([^=]|$)' "$f" | cut -d':' -f1) + done - [ "${#targets[@]}" -eq 0 ] && return 0 + [ "${#targets[@]}" -eq 0 ] && return 0 - # use the targets for completion - while IFS='' read -r line ; do - COMPREPLY+=("$line") - done < <(compgen -W "$(tr ' ' '\n' <<<"${targets[@]}" | sort -u)" -- "${COMP_WORDS[COMP_CWORD]}") + # use the targets for completion + while IFS='' read -r line; do + COMPREPLY+=("$line") + done < <(compgen -W "$(tr ' ' '\n' <<< "${targets[@]}" | sort -u)" -- "${COMP_WORDS[COMP_CWORD]}") - return 0 + return 0 } complete -o nospace -F _makecomplete make diff --git a/completion/available/maven.completion.bash b/completion/available/maven.completion.bash index 312164497d..0af42a882a 100644 --- a/completion/available/maven.completion.bash +++ b/completion/available/maven.completion.bash @@ -1,10 +1,9 @@ #!/usr/bin/env bash # Bash Maven completion -_mvn() -{ - local cmds cur colonprefixes - cmds="clean validate compile test package integration-test \ +_mvn() { + local cmds cur colonprefixes + cmds="clean validate compile test package integration-test \ verify install deploy test-compile site generate-sources \ process-sources generate-resources process-resources \ eclipse:eclipse eclipse:add-maven-repo eclipse:clean \ @@ -18,19 +17,19 @@ _mvn() dependency:sources dependency:tree release:prepare \ release:rollback release:perform --batch-mode" - COMPREPLY=() - cur=${COMP_WORDS[COMP_CWORD]} - # Work-around bash_completion issue where bash interprets a colon - # as a separator. - # Work-around borrowed from the darcs work-around for the same - # issue. - colonprefixes=${cur%"${cur##*:}"} - COMPREPLY=( $(compgen -W '$cmds' -- $cur)) - local i=${#COMPREPLY[*]} - while [ $((--i)) -ge 0 ]; do - COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"} - done + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + # Work-around bash_completion issue where bash interprets a colon + # as a separator. + # Work-around borrowed from the darcs work-around for the same + # issue. + colonprefixes=${cur%"${cur##*:}"} + COMPREPLY=($(compgen -W '$cmds' -- $cur)) + local i=${#COMPREPLY[*]} + while [ $((--i)) -ge 0 ]; do + COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"} + done - return 0 -} && -complete -F _mvn mvn + return 0 +} \ + && complete -F _mvn mvn diff --git a/completion/available/ng.completion.bash b/completion/available/ng.completion.bash index f219b30396..5fedb44459 100644 --- a/completion/available/ng.completion.bash +++ b/completion/available/ng.completion.bash @@ -1,8 +1,8 @@ if _command_exists ng; then - # No longer supported, please see https://github.com/angular/angular-cli/issues/11043 - # Fix courtesy of https://stackoverflow.com/questions/50194674/ng-completion-no-longer-exists - # . <(ng completion --bash) + # No longer supported, please see https://github.com/angular/angular-cli/issues/11043 + # Fix courtesy of https://stackoverflow.com/questions/50194674/ng-completion-no-longer-exists + # . <(ng completion --bash) - NG_COMMANDS="add build config doc e2e generate help lint new run serve test update version xi18n" - complete -W "$NG_COMMANDS" ng + NG_COMMANDS="add build config doc e2e generate help lint new run serve test update version xi18n" + complete -W "$NG_COMMANDS" ng fi diff --git a/completion/available/nvm.completion.bash b/completion/available/nvm.completion.bash index a82b82b61a..4b4147ec44 100644 --- a/completion/available/nvm.completion.bash +++ b/completion/available/nvm.completion.bash @@ -2,7 +2,6 @@ # nvm (Node Version Manager) completion -if [ "$NVM_DIR" ] && [ -r "$NVM_DIR"/bash_completion ]; -then - . "$NVM_DIR"/bash_completion +if [ "$NVM_DIR" ] && [ -r "$NVM_DIR"/bash_completion ]; then + . "$NVM_DIR"/bash_completion fi diff --git a/completion/available/pew.completion.bash b/completion/available/pew.completion.bash index 04e67ecbf5..24b133f9db 100644 --- a/completion/available/pew.completion.bash +++ b/completion/available/pew.completion.bash @@ -1,6 +1,5 @@ # shellcheck shell=bash -if _command_exists pew -then +if _command_exists pew; then source "$(pew shell_config)" fi diff --git a/completion/available/projects.completion.bash b/completion/available/projects.completion.bash index df4f5754dd..196d2bb8a7 100644 --- a/completion/available/projects.completion.bash +++ b/completion/available/projects.completion.bash @@ -1,45 +1,45 @@ # Ensure that we log to doctor so the user can address these issues -_is_function _init_completion || - _log_error '_init_completion not found. Ensure bash-completion 2.0 or newer is installed and configured properly.' -_is_function _rl_enabled || - _log_error '_rl_enabled not found. Ensure bash-completion 2.0 or newer is installed and configured properly.' +_is_function _init_completion \ + || _log_error '_init_completion not found. Ensure bash-completion 2.0 or newer is installed and configured properly.' +_is_function _rl_enabled \ + || _log_error '_rl_enabled not found. Ensure bash-completion 2.0 or newer is installed and configured properly.' _pj() { - _is_function _init_completion || return - _is_function _rl_enabled || return - [ -n "$BASH_IT_PROJECT_PATHS" ] || return - shift - [ "$1" == "open" ] && shift - - local cur prev words cword - _init_completion || return - - local IFS=$'\n' i j k - - compopt -o filenames - - local -r mark_dirs=$(_rl_enabled mark-directories && echo y) - local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y) - - for i in ${BASH_IT_PROJECT_PATHS//:/$'\n'}; do - # create an array of matched subdirs - k="${#COMPREPLY[@]}" - for j in $( compgen -d $i/$cur ); do - if [[ ( $mark_symdirs && -h $j || $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then - j+="/" - fi - COMPREPLY[k++]=${j#$i/} - done - done - - if [[ ${#COMPREPLY[@]} -eq 1 ]]; then - i=${COMPREPLY[0]} - if [[ "$i" == "$cur" && $i != "*/" ]]; then - COMPREPLY[0]="${i}/" - fi - fi - - return 0 + _is_function _init_completion || return + _is_function _rl_enabled || return + [ -n "$BASH_IT_PROJECT_PATHS" ] || return + shift + [ "$1" == "open" ] && shift + + local cur prev words cword + _init_completion || return + + local IFS=$'\n' i j k + + compopt -o filenames + + local -r mark_dirs=$(_rl_enabled mark-directories && echo y) + local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y) + + for i in ${BASH_IT_PROJECT_PATHS//:/$'\n'}; do + # create an array of matched subdirs + k="${#COMPREPLY[@]}" + for j in $(compgen -d $i/$cur); do + if [[ ($mark_symdirs && -L $j || $mark_dirs && ! -L $j) && ! -d ${j#$i/} ]]; then + j+="/" + fi + COMPREPLY[k++]=${j#$i/} + done + done + + if [[ ${#COMPREPLY[@]} -eq 1 ]]; then + i=${COMPREPLY[0]} + if [[ "$i" == "$cur" && $i != "*/" ]]; then + COMPREPLY[0]="${i}/" + fi + fi + + return 0 } complete -F _pj -o nospace pj diff --git a/completion/available/rake.completion.bash b/completion/available/rake.completion.bash index 453354f981..31b7f23b8f 100644 --- a/completion/available/rake.completion.bash +++ b/completion/available/rake.completion.bash @@ -4,14 +4,14 @@ export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} _rakecomplete() { - if [ -f Rakefile ]; then - recent=`ls -t .rake_tasks~ Rakefile **/*.rake 2> /dev/null | head -n 1` - if [[ $recent != '.rake_tasks~' ]]; then - rake --silent --tasks | cut -d " " -f 2 > .rake_tasks~ - fi - COMPREPLY=($(compgen -W "`cat .rake_tasks~`" -- ${COMP_WORDS[COMP_CWORD]})) - return 0 - fi + if [ -f Rakefile ]; then + recent=$(ls -t .rake_tasks~ Rakefile **/*.rake 2> /dev/null | head -n 1) + if [[ $recent != '.rake_tasks~' ]]; then + rake --silent --tasks | cut -d " " -f 2 > .rake_tasks~ + fi + COMPREPLY=($(compgen -W "$(cat .rake_tasks~)" -- ${COMP_WORDS[COMP_CWORD]})) + return 0 + fi } complete -o default -o nospace -F _rakecomplete rake diff --git a/completion/available/sqlmap.completion.bash b/completion/available/sqlmap.completion.bash index 0ad06938dc..20c44582a9 100644 --- a/completion/available/sqlmap.completion.bash +++ b/completion/available/sqlmap.completion.bash @@ -20,7 +20,7 @@ function _sqlmap() { # List directory content --tamper) - COMPREPLY=($(compgen -W "$tamper" -- "$cur")) + IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W "${tamper:-}" -- "$cur")" return 0 ;; --output-dir | -t | -l | -m | -r | --load-cookies | --proxy-file | --sql-file | --shared-lib | --file-write) @@ -32,35 +32,35 @@ function _sqlmap() { return 0 ;; --method) - COMPREPLY=($(compgen -W 'GET POST PUT' -- "$cur")) + IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W 'GET POST PUT' -- "$cur")" return 0 ;; --auth-type) - COMPREPLY=($(compgen -W 'Basic Digest NTLM PKI' -- "$cur")) + IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W 'Basic Digest NTLM PKI' -- "$cur")" return 0 ;; --tor-type) - COMPREPLY=($(compgen -W 'HTTP SOCKS4 SOCKS5' -- "$cur")) + IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W 'HTTP SOCKS4 SOCKS5' -- "$cur")" return 0 ;; -v) - COMPREPLY=($(compgen -W '1 2 3 4 5 6' -- "$cur")) + IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W '1 2 3 4 5 6' -- "$cur")" return 0 ;; --dbms) - COMPREPLY=($(compgen -W 'mysql mssql access postgres' -- "$cur")) + IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W 'mysql mssql access postgres' -- "$cur")" return 0 ;; --level | --crawl) - COMPREPLY=($(compgen -W '1 2 3 4 5' -- "$cur")) + IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W '1 2 3 4 5' -- "$cur")" return 0 ;; --risk) - COMPREPLY=($(compgen -W '0 1 2 3' -- "$cur")) + IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W '0 1 2 3' -- "$cur")" return 0 ;; --technique) - COMPREPLY=($(compgen -W 'B E U S T Q' -- "$cur")) + IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W 'B E U S T Q' -- "$cur")" return 0 ;; -s) @@ -68,7 +68,7 @@ function _sqlmap() { return 0 ;; --dump-format) - COMPREPLY=($(compgen -W 'CSV HTML SQLITE' -- "$cur")) + IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W 'CSV HTML SQLITE' -- "$cur")" return 0 ;; -x) @@ -78,7 +78,8 @@ function _sqlmap() { esac if [[ "$cur" == * ]]; then - COMPREPLY=($(compgen -W '-h --help -hh --version -v -d -u --url -l -x -m -r -g -c --method \ + IFS=' ' read -r -a COMPREPLY <<< "$( + compgen -W '-h --help -hh --version -v -d -u --url -l -x -m -r -g -c --method \ --data --param-del --cookie --cookie-del --load-cookies \ --drop-set-cookie --user-agent --random-agent --host --referer \ --headers --auth-type --auth-cred --auth-private --ignore-401 \ @@ -107,7 +108,8 @@ function _sqlmap() { -z --alert --answers --beep --check-waf --cleanup \ --dependencies --disable-coloring --gpage --identify-waf \ --mobile --page-rank --purge-output --smart \ - --sqlmap-shell --wizard' -- "$cur")) + --sqlmap-shell --wizard' -- "$cur" + )" # this removes any options from the list of completions that have # already been specified somewhere on the command line, as long as # these options can only be used once (in a word, "options", in @@ -141,20 +143,19 @@ function _sqlmap() { --dependencies --disable-coloring --identify-waf \ --mobile --page-rank --purge-output --smart \ --sqlmap-shell --wizard ' - COMPREPLY=($( - ( - while read -d ' ' i; do - [[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] && continue - # flatten array with spaces on either side, - # otherwise we cannot grep on word boundaries of - # first and last word - COMPREPLY=" ${COMPREPLY[@]} " - # remove word from list of completions - COMPREPLY=(${COMPREPLY/ ${i%% *} / }) - done - printf '%s ' "${COMPREPLY[@]}" - ) <<< "${COMP_WORDS[@]}" - )) + + IFS=" " read -r -a COMPREPLY <<< "$( ( + while read -r -d ' ' i; do + [[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] && continue + # flatten array with spaces on either side, + # otherwise we cannot grep on word boundaries of + # first and last word + COMPREPLYSTR=" ${COMPREPLY[*]} " + # remove word from list of completions + IFS=" " read -r -a COMPREPLY <<< "${COMPREPLYSTR/ ${i%% *} / }" + done + printf '%s ' "${COMPREPLY[@]}" + ) <<< "${COMP_WORDS[@]}")" #else #_filedir bat diff --git a/completion/available/ssh.completion.bash b/completion/available/ssh.completion.bash index 1f71f112d6..e95ad76c25 100644 --- a/completion/available/ssh.completion.bash +++ b/completion/available/ssh.completion.bash @@ -4,37 +4,36 @@ export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} _sshcomplete() { - local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" - if [[ ${CURRENT_PROMPT} == *@* ]] ; then - local OPTIONS="-P ${CURRENT_PROMPT/@*/}@ -- ${CURRENT_PROMPT/*@/}" - else - local OPTIONS=" -- ${CURRENT_PROMPT}" - fi + local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" + if [[ ${CURRENT_PROMPT} == *@* ]]; then + local OPTIONS="-P ${CURRENT_PROMPT/@*/}@ -- ${CURRENT_PROMPT/*@/}" + else + local OPTIONS=" -- ${CURRENT_PROMPT}" + fi - # parse all defined hosts from .ssh/config and files included there - for fl in "$HOME/.ssh/config" \ - $(grep "^\s*Include" "$HOME/.ssh/config" | - awk '{for (i=2; i<=NF; i++) print $i}' | - sed -Ee "s|^([^/~])|$HOME/.ssh/\1|" -e "s|^~/|$HOME/|") - do - if [ -r "$fl" ]; then - COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$(grep -i ^Host "$fl" |grep -v '[*!]' | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) ) - fi - done + # parse all defined hosts from .ssh/config and files included there + for fl in "$HOME/.ssh/config" \ + $(grep "^\s*Include" "$HOME/.ssh/config" \ + | awk '{for (i=2; i<=NF; i++) print $i}' \ + | sed -Ee "s|^([^/~])|$HOME/.ssh/\1|" -e "s|^~/|$HOME/|"); do + if [ -r "$fl" ]; then + COMPREPLY=(${COMPREPLY[@]} $(compgen -W "$(grep -i ^Host "$fl" | grep -v '[*!]' | awk '{for (i=2; i<=NF; i++) print $i}')" ${OPTIONS})) + fi + done - # parse all hosts found in .ssh/known_hosts - if [ -r "$HOME/.ssh/known_hosts" ]; then - if grep -v -q -e '^ ssh-rsa' "$HOME/.ssh/known_hosts" ; then - COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$( awk '{print $1}' "$HOME/.ssh/known_hosts" | grep -v ^\| | cut -d, -f 1 | sed -e 's/\[//g' | sed -e 's/\]//g' | cut -d: -f1 | grep -v ssh-rsa)" ${OPTIONS}) ) - fi - fi + # parse all hosts found in .ssh/known_hosts + if [ -r "$HOME/.ssh/known_hosts" ]; then + if grep -v -q -e '^ ssh-rsa' "$HOME/.ssh/known_hosts"; then + COMPREPLY=(${COMPREPLY[@]} $(compgen -W "$(awk '{print $1}' "$HOME/.ssh/known_hosts" | grep -v ^\| | cut -d, -f 1 | sed -e 's/\[//g' | sed -e 's/\]//g' | cut -d: -f1 | grep -v ssh-rsa)" ${OPTIONS})) + fi + fi - # parse hosts defined in /etc/hosts - if [ -r /etc/hosts ]; then - COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$( grep -v '^[[:space:]]*$' /etc/hosts | grep -v '^#' | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) ) - fi + # parse hosts defined in /etc/hosts + if [ -r /etc/hosts ]; then + COMPREPLY=(${COMPREPLY[@]} $(compgen -W "$(grep -v '^[[:space:]]*$' /etc/hosts | grep -v '^#' | awk '{for (i=2; i<=NF; i++) print $i}')" ${OPTIONS})) + fi - return 0 + return 0 } complete -o default -o nospace -F _sshcomplete ssh scp slogin sftp diff --git a/completion/available/terraform.completion.bash b/completion/available/terraform.completion.bash index 1452fca8b2..fcba7d7ba8 100644 --- a/completion/available/terraform.completion.bash +++ b/completion/available/terraform.completion.bash @@ -4,7 +4,7 @@ _command_exists terraform || return # Don't handle completion if it's already managed -complete -p terraform &>/dev/null && return +complete -p terraform &> /dev/null && return # Terraform completes itself complete -C terraform terraform diff --git a/completion/available/test_kitchen.completion.bash b/completion/available/test_kitchen.completion.bash index 25459981e8..6a347c41e9 100644 --- a/completion/available/test_kitchen.completion.bash +++ b/completion/available/test_kitchen.completion.bash @@ -1,30 +1,30 @@ -__kitchen_instance_list () { - # cache to .kitchen.list.yml - if [[ .kitchen.yml -nt .kitchen.list.yml || .kitchen.local.yml -nt .kitchen.list.yml ]]; then - # update list if config has updated - kitchen list --bare > .kitchen.list.yml - fi - cat .kitchen.list.yml +__kitchen_instance_list() { + # cache to .kitchen.list.yml + if [[ .kitchen.yml -nt .kitchen.list.yml || .kitchen.local.yml -nt .kitchen.list.yml ]]; then + # update list if config has updated + kitchen list --bare > .kitchen.list.yml + fi + cat .kitchen.list.yml } -__kitchen_options () { - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - COMPREPLY=() +__kitchen_options() { + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD - 1]}" + COMPREPLY=() - case $prev in - converge|create|destroy|diagnose|list|login|setup|test|verify) - COMPREPLY=( $(compgen -W "$(__kitchen_instance_list)" -- ${cur} )) - return 0 - ;; - driver) - COMPREPLY=( $(compgen -W "create discover help" -- ${cur} )) - return 0 - ;; - *) - COMPREPLY=( $(compgen -W "console converge create destroy driver help init list login setup test verify version" -- ${cur} )) - return 0 - ;; - esac + case $prev in + converge | create | destroy | diagnose | list | login | setup | test | verify) + COMPREPLY=($(compgen -W "$(__kitchen_instance_list)" -- ${cur})) + return 0 + ;; + driver) + COMPREPLY=($(compgen -W "create discover help" -- ${cur})) + return 0 + ;; + *) + COMPREPLY=($(compgen -W "console converge create destroy driver help init list login setup test verify version" -- ${cur})) + return 0 + ;; + esac } complete -F __kitchen_options kitchen diff --git a/completion/available/tmux.completion.bash b/completion/available/tmux.completion.bash index 7992ccb4a0..08a003dea3 100644 --- a/completion/available/tmux.completion.bash +++ b/completion/available/tmux.completion.bash @@ -4,181 +4,189 @@ # See: http://www.debian-administration.org/articles/317 for how to write more. # Usage: Put "source bash_completion_tmux.sh" into your .bashrc -_tmux_expand () -{ - [ "$cur" != "${cur%\\}" ] && cur="$cur"'\'; - if [[ "$cur" == \~*/* ]]; then - eval cur=$cur; - else - if [[ "$cur" == \~* ]]; then - cur=${cur#\~}; - COMPREPLY=($( compgen -P '~' -u $cur )); - return ${#COMPREPLY[@]}; - fi; - fi +_tmux_expand() { + [ "$cur" != "${cur%\\}" ] && cur="$cur"'\' + if [[ "$cur" == \~*/* ]]; then + eval cur=$cur + else + if [[ "$cur" == \~* ]]; then + cur=${cur#\~} + COMPREPLY=($(compgen -P '~' -u $cur)) + return ${#COMPREPLY[@]} + fi + fi } -_tmux_filedir () -{ - local IFS=' -'; - _tmux_expand || return 0; - if [ "$1" = -d ]; then - COMPREPLY=(${COMPREPLY[@]} $( compgen -d -- $cur )); - return 0; - fi; - COMPREPLY=(${COMPREPLY[@]} $( eval compgen -f -- \"$cur\" )) +_tmux_filedir() { + local IFS=' +' + _tmux_expand || return 0 + if [ "$1" = -d ]; then + COMPREPLY=(${COMPREPLY[@]} $(compgen -d -- $cur)) + return 0 + fi + COMPREPLY=(${COMPREPLY[@]} $(eval compgen -f -- \"$cur\")) } function _tmux_complete_client() { - local IFS=$'\n' - local cur="${1}" - COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-clients 2>/dev/null | cut -f 1 -d ':')" -- "${cur}") ) + local IFS=$'\n' + local cur="${1}" + COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-clients 2> /dev/null | cut -f 1 -d ':')" -- "${cur}")) } function _tmux_complete_session() { - local IFS=$'\n' - local cur="${1}" - COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-sessions 2>/dev/null | cut -f 1 -d ':')" -- "${cur}") ) + local IFS=$'\n' + local cur="${1}" + COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-sessions 2> /dev/null | cut -f 1 -d ':')" -- "${cur}")) } function _tmux_complete_window() { - local IFS=$'\n' - local cur="${1}" - local session_name="$(echo "${cur}" | sed 's/\\//g' | cut -d ':' -f 1)" - local sessions + local IFS=$'\n' + local cur="${1}" + local session_name="$(echo "${cur}" | sed 's/\\//g' | cut -d ':' -f 1)" + local sessions - sessions="$(tmux -q list-sessions 2>/dev/null | sed -re 's/([^:]+:).*$/\1/')" - if [[ -n "${session_name}" ]]; then - sessions="${sessions} - $(tmux -q list-windows -t "${session_name}" 2>/dev/null | sed -re 's/^([^:]+):.*$/'"${session_name}"':\1/')" - fi - cur="$(echo "${cur}" | sed -e 's/:/\\\\:/')" - sessions="$(echo "${sessions}" | sed -e 's/:/\\\\:/')" - COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${sessions}" -- "${cur}") ) + sessions="$(tmux -q list-sessions 2> /dev/null | sed -re 's/([^:]+:).*$/\1/')" + if [[ -n "${session_name}" ]]; then + sessions="${sessions} + $(tmux -q list-windows -t "${session_name}" 2> /dev/null | sed -re 's/^([^:]+):.*$/'"${session_name}"':\1/')" + fi + cur="$(echo "${cur}" | sed -e 's/:/\\\\:/')" + sessions="$(echo "${sessions}" | sed -e 's/:/\\\\:/')" + COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "${sessions}" -- "${cur}")) } _tmux() { - local cur prev - local i cmd cmd_index option option_index - local opts="" - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" + local cur prev + local i cmd cmd_index option option_index + local opts="" + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD - 1]}" - if [ ${prev} == -f ]; then - _tmux_filedir - else - # Search for the command - local skip_next=0 - for ((i=1; $i<=$COMP_CWORD; i++)); do - if [[ ${skip_next} -eq 1 ]]; then - #echo "Skipping" - skip_next=0; - elif [[ ${COMP_WORDS[i]} != -* ]]; then - cmd="${COMP_WORDS[i]}" - cmd_index=${i} - break - elif [[ ${COMP_WORDS[i]} == -f ]]; then - skip_next=1 - fi - done + if [ ${prev} == -f ]; then + _tmux_filedir + else + # Search for the command + local skip_next=0 + for ((i = 1; $i <= $COMP_CWORD; i++)); do + if [[ ${skip_next} -eq 1 ]]; then + #echo "Skipping" + skip_next=0 + elif [[ ${COMP_WORDS[i]} != -* ]]; then + cmd="${COMP_WORDS[i]}" + cmd_index=${i} + break + elif [[ ${COMP_WORDS[i]} == -f ]]; then + skip_next=1 + fi + done - # Search for the last option command - skip_next=0 - for ((i=1; $i<=$COMP_CWORD; i++)); do - if [[ ${skip_next} -eq 1 ]]; then - #echo "Skipping" - skip_next=0; - elif [[ ${COMP_WORDS[i]} == -* ]]; then - option="${COMP_WORDS[i]}" - option_index=${i} - if [[ ${COMP_WORDS[i]} == -- ]]; then - break; - fi - elif [[ ${COMP_WORDS[i]} == -f ]]; then - skip_next=1 - fi - done + # Search for the last option command + skip_next=0 + for ((i = 1; $i <= $COMP_CWORD; i++)); do + if [[ ${skip_next} -eq 1 ]]; then + #echo "Skipping" + skip_next=0 + elif [[ ${COMP_WORDS[i]} == -* ]]; then + option="${COMP_WORDS[i]}" + option_index=${i} + if [[ ${COMP_WORDS[i]} == -- ]]; then + break + fi + elif [[ ${COMP_WORDS[i]} == -f ]]; then + skip_next=1 + fi + done - if [[ $COMP_CWORD -le $cmd_index ]]; then - # The user has not specified a command yet - COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux start-server \; list-commands | cut -d' ' -f1)" -- "${cur}") ) - else - case ${cmd} in - attach-session|attach) - case "$prev" in - -t) _tmux_complete_session "${cur}" ;; - *) options="-t -d" ;; - esac ;; - detach-client|detach) - case "$prev" in - -t) _tmux_complete_client "${cur}" ;; - *) options="-t" ;; - esac ;; - lock-client|lockc) - case "$prev" in - -t) _tmux_complete_client "${cur}" ;; - *) options="-t" ;; - esac ;; - lock-session|locks) - case "$prev" in - -t) _tmux_complete_session "${cur}" ;; - *) options="-t -d" ;; - esac ;; - new-session|new) - case "$prev" in - -t) _tmux_complete_session "${cur}" ;; - -[n|d|s]) options="-d -n -s -t --" ;; - *) - if [[ ${COMP_WORDS[option_index]} == -- ]]; then - _command_offset ${option_index} - else - options="-d -n -s -t --" - fi - ;; - esac - ;; - refresh-client|refresh) - case "$prev" in - -t) _tmux_complete_client "${cur}" ;; - *) options="-t" ;; - esac ;; - rename-session|rename) - case "$prev" in - -t) _tmux_complete_session "${cur}" ;; - *) options="-t" ;; - esac ;; - source-file|source) _tmux_filedir ;; - has-session|has|kill-session) - case "$prev" in - -t) _tmux_complete_session "${cur}" ;; - *) options="-t" ;; - esac ;; - suspend-client|suspendc) - case "$prev" in - -t) _tmux_complete_client "${cur}" ;; - *) options="-t" ;; - esac ;; - switch-client|switchc) - case "$prev" in - -c) _tmux_complete_client "${cur}" ;; - -t) _tmux_complete_session "${cur}" ;; - *) options="-l -n -p -c -t" ;; - esac ;; + if [[ $COMP_CWORD -le $cmd_index ]]; then + # The user has not specified a command yet + COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "$(tmux start-server \; list-commands | cut -d' ' -f1)" -- "${cur}")) + else + case ${cmd} in + attach-session | attach) + case "$prev" in + -t) _tmux_complete_session "${cur}" ;; + *) options="-t -d" ;; + esac + ;; + detach-client | detach) + case "$prev" in + -t) _tmux_complete_client "${cur}" ;; + *) options="-t" ;; + esac + ;; + lock-client | lockc) + case "$prev" in + -t) _tmux_complete_client "${cur}" ;; + *) options="-t" ;; + esac + ;; + lock-session | locks) + case "$prev" in + -t) _tmux_complete_session "${cur}" ;; + *) options="-t -d" ;; + esac + ;; + new-session | new) + case "$prev" in + -t) _tmux_complete_session "${cur}" ;; + -[n | d | s]) options="-d -n -s -t --" ;; + *) + if [[ ${COMP_WORDS[option_index]} == -- ]]; then + _command_offset ${option_index} + else + options="-d -n -s -t --" + fi + ;; + esac + ;; + refresh-client | refresh) + case "$prev" in + -t) _tmux_complete_client "${cur}" ;; + *) options="-t" ;; + esac + ;; + rename-session | rename) + case "$prev" in + -t) _tmux_complete_session "${cur}" ;; + *) options="-t" ;; + esac + ;; + source-file | source) _tmux_filedir ;; + has-session | has | kill-session) + case "$prev" in + -t) _tmux_complete_session "${cur}" ;; + *) options="-t" ;; + esac + ;; + suspend-client | suspendc) + case "$prev" in + -t) _tmux_complete_client "${cur}" ;; + *) options="-t" ;; + esac + ;; + switch-client | switchc) + case "$prev" in + -c) _tmux_complete_client "${cur}" ;; + -t) _tmux_complete_session "${cur}" ;; + *) options="-l -n -p -c -t" ;; + esac + ;; - send-keys|send) - case "$option" in - -t) _tmux_complete_window "${cur}" ;; - *) options="-t" ;; - esac ;; - esac # case ${cmd} - fi # command specified - fi # not -f + send-keys | send) + case "$option" in + -t) _tmux_complete_window "${cur}" ;; + *) options="-t" ;; + esac + ;; + esac # case ${cmd} + fi # command specified + fi # not -f - if [[ -n "${options}" ]]; then - COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${options}" -- "${cur}") ) - fi + if [[ -n "${options}" ]]; then + COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "${options}" -- "${cur}")) + fi - return 0 + return 0 } complete -F _tmux tmux diff --git a/completion/available/travis.completion.bash b/completion/available/travis.completion.bash index 49d8f2cc92..f533cde037 100644 --- a/completion/available/travis.completion.bash +++ b/completion/available/travis.completion.bash @@ -1,10 +1,8 @@ # shellcheck shell=bash -if _command_exists travis -then - if [[ -s "${__TRAVIS_COMPLETION_SCRIPT:=${TRAVIS_CONFIG_PATH:-${HOME}/.travis}/travis.sh}" ]] - then +if _command_exists travis; then + if [[ -s "${__TRAVIS_COMPLETION_SCRIPT:=${TRAVIS_CONFIG_PATH:-${HOME}/.travis}/travis.sh}" ]]; then source "${__TRAVIS_COMPLETION_SCRIPT}" fi - unset __TRAVIS_COMPLETION_SCRIPT + unset __TRAVIS_COMPLETION_SCRIPT fi diff --git a/completion/available/vagrant.completion.bash b/completion/available/vagrant.completion.bash index 0803893f2b..31a4ae1369 100644 --- a/completion/available/vagrant.completion.bash +++ b/completion/available/vagrant.completion.bash @@ -22,142 +22,133 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. - __pwdln() { - pwdmod="${PWD}/" - itr=0 - until [[ -z "$pwdmod" ]];do - itr=$(($itr+1)) - pwdmod="${pwdmod#*/}" - done - echo -n $(($itr-1)) + pwdmod="${PWD}/" + itr=0 + until [[ -z "$pwdmod" ]]; do + itr=$(($itr + 1)) + pwdmod="${pwdmod#*/}" + done + echo -n $(($itr - 1)) } __vagrantinvestigate() { - if [ -f "${PWD}/.vagrant" -o -d "${PWD}/.vagrant" ];then - echo "${PWD}/.vagrant" - return 0 - else - pwdmod2="${PWD}" - for (( i=2; i<=$(__pwdln); i++ ));do - pwdmod2="${pwdmod2%/*}" - if [ -f "${pwdmod2}/.vagrant" -o -d "${pwdmod2}/.vagrant" ];then - echo "${pwdmod2}/.vagrant" - return 0 - fi - done - fi - return 1 + if [ -f "${PWD}/.vagrant" -o -d "${PWD}/.vagrant" ]; then + echo "${PWD}/.vagrant" + return 0 + else + pwdmod2="${PWD}" + for ((i = 2; i <= $(__pwdln); i++)); do + pwdmod2="${pwdmod2%/*}" + if [ -f "${pwdmod2}/.vagrant" -o -d "${pwdmod2}/.vagrant" ]; then + echo "${pwdmod2}/.vagrant" + return 0 + fi + done + fi + return 1 } _vagrant() { - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - commands="box cloud destroy global-status halt help hostmanager init login package plugin port powershell provision push rdp reload resume scp snapshot ssh ssh-config status suspend up upload validate vbguest version winrm winrm-config" + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD - 1]}" + commands="box cloud destroy global-status halt help hostmanager init login package plugin port powershell provision push rdp reload resume scp snapshot ssh ssh-config status suspend up upload validate vbguest version winrm winrm-config" - if [ $COMP_CWORD == 1 ] - then - COMPREPLY=($(compgen -W "${commands}" -- ${cur})) - return 0 - fi + if [ $COMP_CWORD == 1 ]; then + COMPREPLY=($(compgen -W "${commands}" -- ${cur})) + return 0 + fi - if [ $COMP_CWORD == 2 ] - then - case "$prev" in - "init") - local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;|sed -e 's/-VAGRANTSLASH-/\//') - COMPREPLY=($(compgen -W "${box_list}" -- ${cur})) - return 0 - ;; - "up") - vagrant_state_file=$(__vagrantinvestigate) || return 1 - if [[ -d $vagrant_state_file ]] - then - vm_list=$(find $vagrant_state_file/machines -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) - fi - local up_commands="--no-provision" - COMPREPLY=($(compgen -W "${up_commands} ${vm_list}" -- ${cur})) - return 0 - ;; - "ssh"|"provision"|"reload"|"halt"|"suspend"|"resume"|"ssh-config") - vagrant_state_file=$(__vagrantinvestigate) || return 1 - if [[ -f $vagrant_state_file ]] - then - running_vm_list=$(grep 'active' $vagrant_state_file | sed -e 's/"active"://' | tr ',' '\n' | cut -d '"' -f 2 | tr '\n' ' ') - else - running_vm_list=$(find $vagrant_state_file -type f -name "id" | awk -F"/" '{print $(NF-2)}') - fi - COMPREPLY=($(compgen -W "${running_vm_list}" -- ${cur})) - return 0 - ;; - "box") - box_commands="add list outdated prune remove repackage update" - COMPREPLY=($(compgen -W "${box_commands}" -- ${cur})) - return 0 - ;; - "plugin") - plugin_commands="expunge install license list repair uninstall update" - COMPREPLY=($(compgen -W "${plugin_commands}" -- ${cur})) - return 0 - ;; - "help") - COMPREPLY=($(compgen -W "${commands}" -- ${cur})) - return 0 - ;; - "snapshot") - snapshot_commands="delete list pop push restore save" - COMPREPLY=($(compgen -W "${snapshot_commands}" -- ${cur})) - return 0 - ;; - *) - ;; - esac - fi + if [ $COMP_CWORD == 2 ]; then + case "$prev" in + "init") + local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sed -e 's/-VAGRANTSLASH-/\//') + COMPREPLY=($(compgen -W "${box_list}" -- ${cur})) + return 0 + ;; + "up") + vagrant_state_file=$(__vagrantinvestigate) || return 1 + if [[ -d $vagrant_state_file ]]; then + vm_list=$(find $vagrant_state_file/machines -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) + fi + local up_commands="--no-provision" + COMPREPLY=($(compgen -W "${up_commands} ${vm_list}" -- ${cur})) + return 0 + ;; + "ssh" | "provision" | "reload" | "halt" | "suspend" | "resume" | "ssh-config") + vagrant_state_file=$(__vagrantinvestigate) || return 1 + if [[ -f $vagrant_state_file ]]; then + running_vm_list=$(grep 'active' $vagrant_state_file | sed -e 's/"active"://' | tr ',' '\n' | cut -d '"' -f 2 | tr '\n' ' ') + else + running_vm_list=$(find $vagrant_state_file -type f -name "id" | awk -F"/" '{print $(NF-2)}') + fi + COMPREPLY=($(compgen -W "${running_vm_list}" -- ${cur})) + return 0 + ;; + "box") + box_commands="add list outdated prune remove repackage update" + COMPREPLY=($(compgen -W "${box_commands}" -- ${cur})) + return 0 + ;; + "plugin") + plugin_commands="expunge install license list repair uninstall update" + COMPREPLY=($(compgen -W "${plugin_commands}" -- ${cur})) + return 0 + ;; + "help") + COMPREPLY=($(compgen -W "${commands}" -- ${cur})) + return 0 + ;; + "snapshot") + snapshot_commands="delete list pop push restore save" + COMPREPLY=($(compgen -W "${snapshot_commands}" -- ${cur})) + return 0 + ;; + *) ;; + esac + fi - if [ $COMP_CWORD == 3 ] - then - action="${COMP_WORDS[COMP_CWORD-2]}" - case "$action" in - "up") - if [ "$prev" == "--no-provision" ]; then - COMPREPLY=($(compgen -W "${vm_list}" -- ${cur})) - return 0 - fi - ;; - "box") - case "$prev" in - "remove"|"repackage") - local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;|sed -e 's/-VAGRANTSLASH-/\//') - COMPREPLY=($(compgen -W "${box_list}" -- ${cur})) - return 0 - ;; - *) - esac - ;; - "snapshot") - if [ "$prev" == "restore" ]; then - COMPREPLY=($(compgen -W "${vm_list}" -- ${cur})) - return 0 - fi - ;; - esac - fi + if [ $COMP_CWORD == 3 ]; then + action="${COMP_WORDS[COMP_CWORD - 2]}" + case "$action" in + "up") + if [ "$prev" == "--no-provision" ]; then + COMPREPLY=($(compgen -W "${vm_list}" -- ${cur})) + return 0 + fi + ;; + "box") + case "$prev" in + "remove" | "repackage") + local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sed -e 's/-VAGRANTSLASH-/\//') + COMPREPLY=($(compgen -W "${box_list}" -- ${cur})) + return 0 + ;; + *) ;; + esac + ;; + "snapshot") + if [ "$prev" == "restore" ]; then + COMPREPLY=($(compgen -W "${vm_list}" -- ${cur})) + return 0 + fi + ;; + esac + fi - if [ $COMP_CWORD == 4 ] - then - action="${COMP_WORDS[COMP_CWORD-3]}" - prev="${COMP_WORDS[COMP_CWORD-2]}" - case "$action" in - "snapshot") - if [ "$prev" == "restore" ]; then - local snapshot_list="$(vagrant snapshot list ${cur} 2>/dev/null | awk '{ORS=" "} /==>/ {next} {print}')" - COMPREPLY=($(compgen -W "${snapshot_list}" -- ${cur})) - return 0 - fi - ;; - *) - ;; - esac - fi + if [ $COMP_CWORD == 4 ]; then + action="${COMP_WORDS[COMP_CWORD - 3]}" + prev="${COMP_WORDS[COMP_CWORD - 2]}" + case "$action" in + "snapshot") + if [ "$prev" == "restore" ]; then + local snapshot_list="$(vagrant snapshot list ${cur} 2> /dev/null | awk '{ORS=" "} /==>/ {next} {print}')" + COMPREPLY=($(compgen -W "${snapshot_list}" -- ${cur})) + return 0 + fi + ;; + *) ;; + esac + fi } complete -F _vagrant vagrant diff --git a/completion/available/virtualbox.completion.bash b/completion/available/virtualbox.completion.bash index 3c29437f97..edb2e714c2 100644 --- a/completion/available/virtualbox.completion.bash +++ b/completion/available/virtualbox.completion.bash @@ -1,222 +1,221 @@ #!/usr/bin/bash _vboxmanage_realopts() { - echo $(vboxmanage|grep -i vboxmanage|cut -d' ' -f2|grep '\['|tr -s '[\[\|\]\n' ' ') - echo " " + echo $(vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | grep '\[' | tr -s '[\[\|\]\n' ' ') + echo " " } __vboxmanage_startvm() { - RUNNING=$(vboxmanage list runningvms | cut -d' ' -f1 | tr -d '"') - TOTAL=$(vboxmanage list vms | cut -d' ' -f1 | tr -d '"') - - AVAILABLE="" - for VM in $TOTAL; do - MATCH=0; - for RUN in $RUNNING "x"; do - if [ "$VM" == "$RUN" ]; then - MATCH=1 - fi - done - (( $MATCH == 0 )) && AVAILABLE="$AVAILABLE $VM " - done - echo $AVAILABLE + RUNNING=$(vboxmanage list runningvms | cut -d' ' -f1 | tr -d '"') + TOTAL=$(vboxmanage list vms | cut -d' ' -f1 | tr -d '"') + + AVAILABLE="" + for VM in $TOTAL; do + MATCH=0 + for RUN in $RUNNING "x"; do + if [ "$VM" == "$RUN" ]; then + MATCH=1 + fi + done + (($MATCH == 0)) && AVAILABLE="$AVAILABLE $VM " + done + echo $AVAILABLE } __vboxmanage_list() { - INPUT=$(vboxmanage list | tr -s '[\[\]\|\n]' ' ' | cut -d' ' -f4-) + INPUT=$(vboxmanage list | tr -s '[\[\]\|\n]' ' ' | cut -d' ' -f4-) - PRUNED="" - if [ "$1" == "long" ]; then - for WORD in $INPUT; do - [ "$WORD" == "-l" ] && continue; - [ "$WORD" == "--long" ] && continue; + PRUNED="" + if [ "$1" == "long" ]; then + for WORD in $INPUT; do + [ "$WORD" == "-l" ] && continue + [ "$WORD" == "--long" ] && continue - PRUNED="$PRUNED $WORD" - done - else - PRUNED=$INPUT - fi + PRUNED="$PRUNED $WORD" + done + else + PRUNED=$INPUT + fi - echo $PRUNED + echo $PRUNED } - __vboxmanage_list_vms() { - VMS="" - if [ "x$1" == "x" ]; then - SEPARATOR=" " - else - SEPARATOR=$1 - fi - - for VM in $(vboxmanage list vms | cut -d' ' -f1 | tr -d '"'); do - [ "$VMS" != "" ] && VMS="${VMS}${SEPARATOR}" - VMS="${VMS}${VM}" - done - - echo $VMS + VMS="" + if [ "x$1" == "x" ]; then + SEPARATOR=" " + else + SEPARATOR=$1 + fi + + for VM in $(vboxmanage list vms | cut -d' ' -f1 | tr -d '"'); do + [ "$VMS" != "" ] && VMS="${VMS}${SEPARATOR}" + VMS="${VMS}${VM}" + done + + echo $VMS } __vboxmanage_list_runningvms() { - VMS="" - if [ "$1" == "" ]; then - SEPARATOR=" " - else - SEPARATOR=$1 - fi + VMS="" + if [ "$1" == "" ]; then + SEPARATOR=" " + else + SEPARATOR=$1 + fi - for VM in $(vboxmanage list runningvms | cut -d' ' -f1 | tr -d '"'); do - [ "$VMS" != "" ] && VMS="${VMS}${SEPARATOR}" - VMS="${VMS}${VM}" - done + for VM in $(vboxmanage list runningvms | cut -d' ' -f1 | tr -d '"'); do + [ "$VMS" != "" ] && VMS="${VMS}${SEPARATOR}" + VMS="${VMS}${VM}" + done - echo $VMS + echo $VMS } __vboxmanage_controlvm() { - echo "pause resume reset poweroff savestate acpipowerbutton" - echo "acpisleepbutton keyboardputscancode guestmemoryballoon" - echo "gueststatisticsinterval usbattach usbdetach vrde vrdeport" - echo "vrdeproperty vrdevideochannelquality setvideomodehint" - echo "screenshotpng setcredentials teleport plugcpu unplugcpu" - echo "cpuexecutioncap" - -# setlinkstate<1-N> -# nic<1-N> null|nat|bridged|intnet|hostonly|generic -# [] | - # nictrace<1-N> on|off - # nictracefile<1-N> - # nicproperty<1-N> name=[value] - # natpf<1-N> [],tcp|udp,[], - # ,[], - # natpf<1-N> delete + echo "pause resume reset poweroff savestate acpipowerbutton" + echo "acpisleepbutton keyboardputscancode guestmemoryballoon" + echo "gueststatisticsinterval usbattach usbdetach vrde vrdeport" + echo "vrdeproperty vrdevideochannelquality setvideomodehint" + echo "screenshotpng setcredentials teleport plugcpu unplugcpu" + echo "cpuexecutioncap" + + # setlinkstate<1-N> + # nic<1-N> null|nat|bridged|intnet|hostonly|generic + # [] | + # nictrace<1-N> on|off + # nictracefile<1-N> + # nicproperty<1-N> name=[value] + # natpf<1-N> [],tcp|udp,[], + # ,[], + # natpf<1-N> delete } __vboxmanage_default() { - realopts=$(_vboxmanage_realopts) - opts=$realopts$(vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | grep -v '\[' | sort | uniq) - pruned="" - - # echo "" - # echo "DEBUG: cur: $cur, prev: $prev" - # echo "DEBUG: default: |$p1|$p2|$p3|$p4|" - case ${cur} in - -*) - echo $opts - # COMPREPLY=($(compgen -W "${opts}" -- ${cur})) - return 0 - ;; - esac; - - for WORD in $opts; do - MATCH=0 - for OPT in "${COMP_WORDS[@]}"; do - # opts=$(echo ${opts} | grep -v $OPT); - if [ "$OPT" == "$WORD" ]; then - MATCH=1 - break; - fi - if [ "$OPT" == "-v" ] && [ "$WORD" == "--version" ]; then - MATCH=1 - break; - fi - if [ "$OPT" == "--version" ] && [ "$WORD" == "-v" ]; then - MATCH=1 - break; - fi - if [ "$OPT" == "-q" ] && [ "$WORD" == "--nologo" ]; then - MATCH=1 - break; - fi - if [ "$OPT" == "--nologo" ] && [ "$WORD" == "-q" ]; then - MATCH=1 - break; - fi - done - (( $MATCH == 1 )) && continue; - pruned="$pruned $WORD" - - done - - # COMPREPLY=($(compgen -W "${pruned}" -- ${cur})) - echo $pruned - return 0 + realopts=$(_vboxmanage_realopts) + opts=$realopts$(vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | grep -v '\[' | sort | uniq) + pruned="" + + # echo "" + # echo "DEBUG: cur: $cur, prev: $prev" + # echo "DEBUG: default: |$p1|$p2|$p3|$p4|" + case ${cur} in + -*) + echo $opts + # COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + ;; + esac + + for WORD in $opts; do + MATCH=0 + for OPT in "${COMP_WORDS[@]}"; do + # opts=$(echo ${opts} | grep -v $OPT); + if [ "$OPT" == "$WORD" ]; then + MATCH=1 + break + fi + if [ "$OPT" == "-v" ] && [ "$WORD" == "--version" ]; then + MATCH=1 + break + fi + if [ "$OPT" == "--version" ] && [ "$WORD" == "-v" ]; then + MATCH=1 + break + fi + if [ "$OPT" == "-q" ] && [ "$WORD" == "--nologo" ]; then + MATCH=1 + break + fi + if [ "$OPT" == "--nologo" ] && [ "$WORD" == "-q" ]; then + MATCH=1 + break + fi + done + (($MATCH == 1)) && continue + pruned="$pruned $WORD" + + done + + # COMPREPLY=($(compgen -W "${pruned}" -- ${cur})) + echo $pruned + return 0 } _vboxmanage() { - # vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | sort | uniq - local cur p1 p2 p3 p4 opts - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - - # echo "cur: |$cur|" - # echo "prev: |$prev|" - - # In case current is complete command - case $cur in - startvm|list|controlvm) - COMPREPLY=($(compgen -W "$cur ")) - return 0 - ;; - esac - - case $prev in - -v|--version) - return 0 - ;; - - -l|--long) - opts=$(__vboxmanage_list "long") - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) - return 0 - ;; - startvm|list) - opts=$(__vboxmanage_$prev) - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) - return 0 - ;; - --type) - COMPREPLY=($(compgen -W "gui headless" -- ${cur})) - return 0 - ;; - gui|headless) - # Done. no more completion possible - return 0 - ;; - vboxmanage|-q|--nologo) - # echo "Got vboxmanage" - opts=$(__vboxmanage_default) - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) - return 0 - ;; - controlvm) - opts=$(__vboxmanage_list_vms) - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) - return 0 - ;; - esac - - for VM in $(__vboxmanage_list_vms); do - if [ "$VM" == "$prev" ]; then - pprev=${COMP_WORDS[COMP_CWORD-2]} - # echo "previous: $pprev" - case $pprev in - startvm) - opts="--type" - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) - return 0 - ;; - controlvm) - opts=$(__vboxmanage_controlvm) - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) - return 0; - ;; - esac - fi - done - - # echo "Got to end withoug completion" + # vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | sort | uniq + local cur p1 p2 p3 p4 opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD - 1]}" + + # echo "cur: |$cur|" + # echo "prev: |$prev|" + + # In case current is complete command + case $cur in + startvm | list | controlvm) + COMPREPLY=($(compgen -W "$cur ")) + return 0 + ;; + esac + + case $prev in + -v | --version) + return 0 + ;; + + -l | --long) + opts=$(__vboxmanage_list "long") + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + ;; + startvm | list) + opts=$(__vboxmanage_$prev) + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + ;; + --type) + COMPREPLY=($(compgen -W "gui headless" -- ${cur})) + return 0 + ;; + gui | headless) + # Done. no more completion possible + return 0 + ;; + vboxmanage | -q | --nologo) + # echo "Got vboxmanage" + opts=$(__vboxmanage_default) + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + ;; + controlvm) + opts=$(__vboxmanage_list_vms) + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + ;; + esac + + for VM in $(__vboxmanage_list_vms); do + if [ "$VM" == "$prev" ]; then + pprev=${COMP_WORDS[COMP_CWORD - 2]} + # echo "previous: $pprev" + case $pprev in + startvm) + opts="--type" + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + ;; + controlvm) + opts=$(__vboxmanage_controlvm) + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + ;; + esac + fi + done + + # echo "Got to end withoug completion" } complete -F _vboxmanage vboxmanage diff --git a/plugins/available/boot2docker.plugin.bash b/plugins/available/boot2docker.plugin.bash index f19e91ef84..21395ea9bd 100644 --- a/plugins/available/boot2docker.plugin.bash +++ b/plugins/available/boot2docker.plugin.bash @@ -4,7 +4,7 @@ about-plugin 'Helpers to get Docker setup correctly for boot2docker' # Note, this might need to be different if you have an older version # of boot2docker, or its configured for a different IP if [[ "$OSTYPE" == 'darwin'* ]]; then - export DOCKER_HOST="tcp://192.168.59.103:2376" - export DOCKER_CERT_PATH="~/.boot2docker/certs/boot2docker-vm" - export DOCKER_TLS_VERIFY=1 + export DOCKER_HOST="tcp://192.168.59.103:2376" + export DOCKER_CERT_PATH="~/.boot2docker/certs/boot2docker-vm" + export DOCKER_TLS_VERIFY=1 fi diff --git a/plugins/available/cht-sh.plugin.bash b/plugins/available/cht-sh.plugin.bash index 63e3c9b74f..722f40f506 100644 --- a/plugins/available/cht-sh.plugin.bash +++ b/plugins/available/cht-sh.plugin.bash @@ -2,8 +2,8 @@ cite about-plugin about-plugin 'Simplify `curl cht.sh/` to `cht.sh `' # Play nicely if user already installed cht.sh cli tool -if ! _command_exists cht.sh ; then - function cht.sh () { +if ! _command_exists cht.sh; then + function cht.sh() { about 'Executes a cht.sh curl query using the provided arguments' param ' [ ( topic [sub-topic] ) | ~keyword ] [ :list | :help | :learn ]' example '$ cht.sh :help' @@ -15,7 +15,10 @@ if ! _command_exists cht.sh ; then group 'cht-sh' # Separate arguments with '/', preserving spaces within them - local query=$(IFS=/ ; echo "$*") + local query=$( + IFS=/ + echo "$*" + ) curl "cht.sh/${query}" } fi diff --git a/plugins/available/docker.plugin.bash b/plugins/available/docker.plugin.bash index 2632c3cc6b..ff0e1997dc 100644 --- a/plugins/available/docker.plugin.bash +++ b/plugins/available/docker.plugin.bash @@ -2,80 +2,80 @@ cite about-plugin about-plugin 'Helpers to more easily work with Docker' function docker-remove-most-recent-container() { - about 'attempt to remove the most recent container from docker ps -a' - group 'docker' - docker ps -ql | xargs docker rm + about 'attempt to remove the most recent container from docker ps -a' + group 'docker' + docker ps -ql | xargs docker rm } function docker-remove-most-recent-image() { - about 'attempt to remove the most recent image from docker images' - group 'docker' - docker images -q | head -1 | xargs docker rmi + about 'attempt to remove the most recent image from docker images' + group 'docker' + docker images -q | head -1 | xargs docker rmi } function docker-remove-stale-assets() { - about 'attempt to remove exited containers and dangling images' - group 'docker' - docker ps --filter status=exited -q | xargs docker rm --volumes - docker images --filter dangling=true -q | xargs docker rmi + about 'attempt to remove exited containers and dangling images' + group 'docker' + docker ps --filter status=exited -q | xargs docker rm --volumes + docker images --filter dangling=true -q | xargs docker rmi } function docker-enter() { - about 'enter the specified docker container using bash' - group 'docker' - param '1: Name of the container to enter' - example 'docker-enter oracle-xe' + about 'enter the specified docker container using bash' + group 'docker' + param '1: Name of the container to enter' + example 'docker-enter oracle-xe' - docker exec -it "$@" /bin/bash; + docker exec -it "$@" /bin/bash } function docker-remove-images() { - about 'attempt to remove images with supplied tags or all if no tags are supplied' - group 'docker' - if [ -z "$1" ]; then - docker rmi $(docker images -q) - else - DOCKER_IMAGES="" - for IMAGE_ID in $@; do DOCKER_IMAGES="$DOCKER_IMAGES\|$IMAGE_ID"; done - # Find the image IDs for the supplied tags - ID_ARRAY=($(docker images | grep "${DOCKER_IMAGES:2}" | awk {'print $3'})) - # Strip out duplicate IDs before attempting to remove the image(s) - docker rmi $(echo ${ID_ARRAY[@]} | tr ' ' '\n' | sort -u | tr '\n' ' ') - fi + about 'attempt to remove images with supplied tags or all if no tags are supplied' + group 'docker' + if [ -z "$1" ]; then + docker rmi $(docker images -q) + else + DOCKER_IMAGES="" + for IMAGE_ID in $@; do DOCKER_IMAGES="$DOCKER_IMAGES\|$IMAGE_ID"; done + # Find the image IDs for the supplied tags + ID_ARRAY=($(docker images | grep "${DOCKER_IMAGES:2}" | awk {'print $3'})) + # Strip out duplicate IDs before attempting to remove the image(s) + docker rmi $(echo ${ID_ARRAY[@]} | tr ' ' '\n' | sort -u | tr '\n' ' ') + fi } function docker-image-dependencies() { - about 'attempt to create a Graphiz image of the supplied image ID dependencies' - group 'docker' - if hash dot 2>/dev/null; then - OUT=$(mktemp -t docker-viz-XXXX.png) - docker images -viz | dot -Tpng > $OUT - case $OSTYPE in - linux*) - xdg-open $OUT - ;; - darwin*) - open $OUT - ;; - esac - else - >&2 echo "Can't show dependencies; Graphiz is not installed" - fi + about 'attempt to create a Graphiz image of the supplied image ID dependencies' + group 'docker' + if hash dot 2> /dev/null; then + OUT=$(mktemp -t docker-viz-XXXX.png) + docker images -viz | dot -Tpng > $OUT + case $OSTYPE in + linux*) + xdg-open $OUT + ;; + darwin*) + open $OUT + ;; + esac + else + >&2 echo "Can't show dependencies; Graphiz is not installed" + fi } function docker-runtime-environment() { - about 'attempt to list the environmental variables of the supplied image ID' - group 'docker' - docker run "$@" env + about 'attempt to list the environmental variables of the supplied image ID' + group 'docker' + docker run "$@" env } function docker-archive-content() { - about 'show the content of the provided Docker image archive' - group 'docker' - param '1: image archive name' - example 'docker-archive-content images.tar.gz' + about 'show the content of the provided Docker image archive' + group 'docker' + param '1: image archive name' + example 'docker-archive-content images.tar.gz' - if [ -n "$1" ]; then - tar -xzOf $1 manifest.json | jq '[.[] | .RepoTags] | add' - fi + if [ -n "$1" ]; then + tar -xzOf $1 manifest.json | jq '[.[] | .RepoTags] | add' + fi } diff --git a/plugins/available/explain.plugin.bash b/plugins/available/explain.plugin.bash index ab7b4a0cdb..d5ce0b451f 100644 --- a/plugins/available/explain.plugin.bash +++ b/plugins/available/explain.plugin.bash @@ -1,23 +1,23 @@ cite about-plugin about-plugin 'mankier.com explain function to explain other commands' -explain () { - about 'explain any bash command via mankier.com manpage API' - param '1: Name of the command to explain' - example '$ explain # interactive mode. Type commands to explain in REPL' - example '$ explain '"'"'cmd -o | ...'"'"' # one quoted command to explain it.' - group 'explain' +explain() { + about 'explain any bash command via mankier.com manpage API' + param '1: Name of the command to explain' + example '$ explain # interactive mode. Type commands to explain in REPL' + example '$ explain '"'"'cmd -o | ...'"'"' # one quoted command to explain it.' + group 'explain' - if [ "$#" -eq 0 ]; then - while read -p "Command: " cmd; do - curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$cmd" - done - echo "Bye!" - elif [ "$#" -eq 1 ]; then - curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$1" - else - echo "Usage" - echo "explain interactive mode." - echo "explain 'cmd -o | ...' one quoted command to explain it." - fi + if [ "$#" -eq 0 ]; then + while read -p "Command: " cmd; do + curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$cmd" + done + echo "Bye!" + elif [ "$#" -eq 1 ]; then + curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$1" + else + echo "Usage" + echo "explain interactive mode." + echo "explain 'cmd -o | ...' one quoted command to explain it." + fi } diff --git a/plugins/available/extract.plugin.bash b/plugins/available/extract.plugin.bash index 9fc05c7d92..909b4f136d 100644 --- a/plugins/available/extract.plugin.bash +++ b/plugins/available/extract.plugin.bash @@ -3,71 +3,74 @@ about-plugin 'one command to extract them all...' # extract file(s) from compressed status extract() { - local opt - local OPTIND=1 - while getopts "hv" opt; do - case "$opt" in - h) - cat < options: -h show this message and exit -v verbosely list files processed End-Of-Usage - return - ;; - v) - local -r verbose='v' - ;; - ?) - extract -h >&2 - return 1 - ;; - esac - done - shift $((OPTIND-1)) + return + ;; + v) + local -r verbose='v' + ;; + ?) + extract -h >&2 + return 1 + ;; + esac + done + shift $((OPTIND - 1)) - [ $# -eq 0 ] && extract -h && return 1 - while [ $# -gt 0 ]; do - if [[ ! -f "$1" ]]; then - echo "extract: '$1' is not a valid file" >&2 - shift - continue - fi + [ $# -eq 0 ] && extract -h && return 1 + while [ $# -gt 0 ]; do + if [[ ! -f "$1" ]]; then + echo "extract: '$1' is not a valid file" >&2 + shift + continue + fi - local -r filename=$(basename -- $1) - local -r filedirname=$(dirname -- $1) - local targetdirname=$(sed 's/\(\.tar\.bz2$\|\.tbz$\|\.tbz2$\|\.tar\.gz$\|\.tgz$\|\.tar$\|\.tar\.xz$\|\.txz$\|\.tar\.Z$\|\.7z$\|\.nupkg$\|\.zip$\|\.war$\|\.jar$\)//g' <<< $filename) - if [ "$filename" = "$targetdirname" ]; then - # archive type either not supported or it doesn't need dir creation - targetdirname="" - else - mkdir -v "$filedirname/$targetdirname" - fi + local -r filename=$(basename -- $1) + local -r filedirname=$(dirname -- $1) + local targetdirname=$(sed 's/\(\.tar\.bz2$\|\.tbz$\|\.tbz2$\|\.tar\.gz$\|\.tgz$\|\.tar$\|\.tar\.xz$\|\.txz$\|\.tar\.Z$\|\.7z$\|\.nupkg$\|\.zip$\|\.war$\|\.jar$\)//g' <<< $filename) + if [ "$filename" = "$targetdirname" ]; then + # archive type either not supported or it doesn't need dir creation + targetdirname="" + else + mkdir -v "$filedirname/$targetdirname" + fi - if [ -f "$1" ]; then - case "$1" in - *.tar.bz2|*.tbz|*.tbz2) tar "x${verbose}jf" "$1" -C "$filedirname/$targetdirname" ;; - *.tar.gz|*.tgz) tar "x${verbose}zf" "$1" -C "$filedirname/$targetdirname" ;; - *.tar.xz|*.txz) tar "x${verbose}Jf" "$1" -C "$filedirname/$targetdirname" ;; - *.tar.Z) tar "x${verbose}Zf" "$1" -C "$filedirname/$targetdirname" ;; - *.bz2) bunzip2 "$1" ;; - *.deb) dpkg-deb -x${verbose} "$1" "${1:0:-4}" ;; - *.pax.gz) gunzip "$1"; set -- "$@" "${1:0:-3}" ;; - *.gz) gunzip "$1" ;; - *.pax) pax -r -f "$1" ;; - *.pkg) pkgutil --expand "$1" "${1:0:-4}" ;; - *.rar) unrar x "$1" ;; - *.rpm) rpm2cpio "$1" | cpio -idm${verbose} ;; - *.tar) tar "x${verbose}f" "$1" -C "$filedirname/$targetdirname" ;; - *.xz) xz --decompress "$1" ;; - *.zip|*.war|*.jar|*.nupkg) unzip "$1" -d "$filedirname/$targetdirname" ;; - *.Z) uncompress "$1" ;; - *.7z) 7za x -o"$filedirname/$targetdirname" "$1" ;; - *) echo "'$1' cannot be extracted via extract" >&2;; - esac - fi + if [ -f "$1" ]; then + case "$1" in + *.tar.bz2 | *.tbz | *.tbz2) tar "x${verbose}jf" "$1" -C "$filedirname/$targetdirname" ;; + *.tar.gz | *.tgz) tar "x${verbose}zf" "$1" -C "$filedirname/$targetdirname" ;; + *.tar.xz | *.txz) tar "x${verbose}Jf" "$1" -C "$filedirname/$targetdirname" ;; + *.tar.Z) tar "x${verbose}Zf" "$1" -C "$filedirname/$targetdirname" ;; + *.bz2) bunzip2 "$1" ;; + *.deb) dpkg-deb -x${verbose} "$1" "${1:0:-4}" ;; + *.pax.gz) + gunzip "$1" + set -- "$@" "${1:0:-3}" + ;; + *.gz) gunzip "$1" ;; + *.pax) pax -r -f "$1" ;; + *.pkg) pkgutil --expand "$1" "${1:0:-4}" ;; + *.rar) unrar x "$1" ;; + *.rpm) rpm2cpio "$1" | cpio -idm${verbose} ;; + *.tar) tar "x${verbose}f" "$1" -C "$filedirname/$targetdirname" ;; + *.xz) xz --decompress "$1" ;; + *.zip | *.war | *.jar | *.nupkg) unzip "$1" -d "$filedirname/$targetdirname" ;; + *.Z) uncompress "$1" ;; + *.7z) 7za x -o"$filedirname/$targetdirname" "$1" ;; + *) echo "'$1' cannot be extracted via extract" >&2 ;; + esac + fi - shift - done + shift + done } diff --git a/plugins/available/fzf.plugin.bash b/plugins/available/fzf.plugin.bash index 21182ac24f..edff2b4523 100644 --- a/plugins/available/fzf.plugin.bash +++ b/plugins/available/fzf.plugin.bash @@ -4,39 +4,39 @@ cite about-plugin about-plugin 'load fzf, if you are using it' -if [ -r ~/.fzf.bash ] ; then - source ~/.fzf.bash -elif [ -r "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash ] ; then - source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash +if [ -r ~/.fzf.bash ]; then + source ~/.fzf.bash +elif [ -r "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash ]; then + source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash fi # No need to continue if the command is not present _command_exists fzf || return -if [ -z ${FZF_DEFAULT_COMMAND+x} ] && _command_exists fd ; then - export FZF_DEFAULT_COMMAND='fd --type f' +if [ -z ${FZF_DEFAULT_COMMAND+x} ] && _command_exists fd; then + export FZF_DEFAULT_COMMAND='fd --type f' fi fe() { - about "Open the selected file in the default editor" - group "fzf" - param "1: Search term" - example "fe foo" - - local IFS=$'\n' - local files - files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0)) - [[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}" + about "Open the selected file in the default editor" + group "fzf" + param "1: Search term" + example "fe foo" + + local IFS=$'\n' + local files + files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0)) + [[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}" } fcd() { - about "cd to the selected directory" - group "fzf" - param "1: Directory to browse, or . if omitted" - example "fcd aliases" - - local dir - dir=$(find ${1:-.} -path '*/\.*' -prune \ - -o -type d -print 2> /dev/null | fzf +m) && - cd "$dir" + about "cd to the selected directory" + group "fzf" + param "1: Directory to browse, or . if omitted" + example "fcd aliases" + + local dir + dir=$(find ${1:-.} -path '*/\.*' -prune \ + -o -type d -print 2> /dev/null | fzf +m) \ + && cd "$dir" } diff --git a/plugins/available/gitstatus.plugin.bash b/plugins/available/gitstatus.plugin.bash index 9df65a82c1..a48864e38d 100644 --- a/plugins/available/gitstatus.plugin.bash +++ b/plugins/available/gitstatus.plugin.bash @@ -2,11 +2,11 @@ cite about-plugin about-plugin 'speeds up your life by using gitstatus for git status calculations. install from https://github.com/romkatv/gitstatus' function gitstatus_on_disable() { - about 'Destructor of gitstatus plugin' - group 'gitstatus' + about 'Destructor of gitstatus plugin' + group 'gitstatus' - unset SCM_GIT_USE_GITSTATUS - _command_exists gitstatus_stop && gitstatus_stop + unset SCM_GIT_USE_GITSTATUS + _command_exists gitstatus_stop && gitstatus_stop } # No scm-check @@ -17,10 +17,10 @@ function gitstatus_on_disable() { : "${SCM_GIT_GITSTATUS_DIR:="$HOME/gitstatus"}" if [[ -d ${SCM_GIT_GITSTATUS_DIR} ]]; then - source "${SCM_GIT_GITSTATUS_DIR}/gitstatus.plugin.sh" - # Start the actual gitstatus binary - gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1 - export SCM_GIT_USE_GITSTATUS=true + source "${SCM_GIT_GITSTATUS_DIR}/gitstatus.plugin.sh" + # Start the actual gitstatus binary + gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1 + export SCM_GIT_USE_GITSTATUS=true else _log_warning "Could not find gitstatus directory in ${SCM_GIT_GITSTATUS_DIR}. Please specify directory location using SCM_GIT_GITSTATUS_DIR." fi diff --git a/plugins/available/hg.plugin.bash b/plugins/available/hg.plugin.bash index 020b920db4..7990b00631 100644 --- a/plugins/available/hg.plugin.bash +++ b/plugins/available/hg.plugin.bash @@ -2,24 +2,24 @@ cite about-plugin about-plugin 'hg helper functions' hg_dirty() { - about 'displays dirty status of hg repository' - group 'hg' + about 'displays dirty status of hg repository' + group 'hg' - hg status --no-color 2> /dev/null \ - | awk '$1 == "?" { print "?" } $1 != "?" { print "!" }' \ - | sort | uniq | head -c1 + hg status --no-color 2> /dev/null \ + | awk '$1 == "?" { print "?" } $1 != "?" { print "!" }' \ + | sort | uniq | head -c1 } hg_in_repo() { - about 'determine if pwd is an hg repo' - group 'hg' + about 'determine if pwd is an hg repo' + group 'hg' - [[ `hg branch 2> /dev/null` ]] && echo 'on ' + [[ $(hg branch 2> /dev/null) ]] && echo 'on ' } hg_branch() { - about 'display current hg branch' - group 'hg' + about 'display current hg branch' + group 'hg' - hg branch 2> /dev/null + hg branch 2> /dev/null } diff --git a/plugins/available/javascript.plugin.bash b/plugins/available/javascript.plugin.bash index e8037b9df7..a6266b4d31 100644 --- a/plugins/available/javascript.plugin.bash +++ b/plugins/available/javascript.plugin.bash @@ -7,35 +7,33 @@ about-plugin 'download jquery files into current project' [[ -z "$JQUERY_UI_VERSION_NUMBER" ]] && JQUERY_UI_VERSION_NUMBER="1.8.13" function rails_jquery { - about 'download rails.js into public/javascripts' - group 'javascript' + about 'download rails.js into public/javascripts' + group 'javascript' - curl -o public/javascripts/rails.js http://github.com/rails/jquery-ujs/raw/master/src/rails.js + curl -o public/javascripts/rails.js http://github.com/rails/jquery-ujs/raw/master/src/rails.js } function jquery_install { - about 'download jquery.js into public/javascripts' - group 'javascript' - - if [ -z "$1" ] - then - version=$JQUERY_VERSION_NUMBER - else - version="$1" - fi - curl -o public/javascripts/jquery.js "http://ajax.googleapis.com/ajax/libs/jquery/$version/jquery.min.js" + about 'download jquery.js into public/javascripts' + group 'javascript' + + if [ -z "$1" ]; then + version=$JQUERY_VERSION_NUMBER + else + version="$1" + fi + curl -o public/javascripts/jquery.js "http://ajax.googleapis.com/ajax/libs/jquery/$version/jquery.min.js" } function jquery_ui_install { - about 'download jquery_us.js into public/javascripts' - group 'javascript' + about 'download jquery_us.js into public/javascripts' + group 'javascript' - if [ -z "$1" ] - then - version=$JQUERY_UI_VERSION_NUMBER - else - version="$1" - fi + if [ -z "$1" ]; then + version=$JQUERY_UI_VERSION_NUMBER + else + version="$1" + fi - curl -o public/javascripts/jquery_ui.js "http://ajax.googleapis.com/ajax/libs/jqueryui/$version/jquery-ui.min.js" + curl -o public/javascripts/jquery_ui.js "http://ajax.googleapis.com/ajax/libs/jqueryui/$version/jquery-ui.min.js" } diff --git a/plugins/available/jenv.plugin.bash b/plugins/available/jenv.plugin.bash index 773a992116..8c36da5166 100644 --- a/plugins/available/jenv.plugin.bash +++ b/plugins/available/jenv.plugin.bash @@ -5,18 +5,18 @@ about-plugin 'load jenv, if you are using it' # - Check if in $PATH already # - Check if installed manually to $JENV_ROOT # - Check if installed manually to $HOME -_command_exists jenv || - [[ -n "$JENV_ROOT" && -x "$JENV_ROOT/bin/jenv" ]] || - [[ -x "$HOME/.jenv/bin/jenv" ]] || - return +_command_exists jenv \ + || [[ -n "$JENV_ROOT" && -x "$JENV_ROOT/bin/jenv" ]] \ + || [[ -x "$HOME/.jenv/bin/jenv" ]] \ + || return # Set JENV_ROOT, if not already set export JENV_ROOT="${JENV_ROOT:-$HOME/.jenv}" # Add JENV_ROOT/bin to PATH, if that's where it's installed -! _command_exists jenv && - [[ -x "$JENV_ROOT/bin/jenv" ]] && - pathmunge "$JENV_ROOT/bin" +! _command_exists jenv \ + && [[ -x "$JENV_ROOT/bin/jenv" ]] \ + && pathmunge "$JENV_ROOT/bin" # Initialize jenv eval "$(jenv init - bash)" diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index 4dc4c6d630..72a94e0396 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -12,28 +12,25 @@ export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" # first check if NVM is managed by brew NVM_BREW_PREFIX="" -if _bash_it_homebrew_check -then - NVM_BREW_PREFIX=$(brew --prefix nvm 2>/dev/null) +if _bash_it_homebrew_check; then + NVM_BREW_PREFIX=$(brew --prefix nvm 2> /dev/null) fi # This loads nvm -if [[ -n "$NVM_BREW_PREFIX" && -s "${NVM_BREW_PREFIX}/nvm.sh" ]] -then - source "${NVM_BREW_PREFIX}/nvm.sh" +if [[ -n "$NVM_BREW_PREFIX" && -s "${NVM_BREW_PREFIX}/nvm.sh" ]]; then + source "${NVM_BREW_PREFIX}/nvm.sh" else - [[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" + [[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" fi -if ! _command_exists nvm -then - function nvm() { - echo "Bash-it no longer bundles the nvm script. Please install the latest version from" - echo "" - echo "https://github.com/creationix/nvm.git" - echo "" - echo "if you want to use nvm. You can keep this plugin enabled once you have installed nvm." - } +if ! _command_exists nvm; then + function nvm() { + echo "Bash-it no longer bundles the nvm script. Please install the latest version from" + echo "" + echo "https://github.com/creationix/nvm.git" + echo "" + echo "if you want to use nvm. You can keep this plugin enabled once you have installed nvm." + } - nvm + nvm fi diff --git a/plugins/available/pack.plugin.bash b/plugins/available/pack.plugin.bash index a63a8e5759..2afb2d95c2 100644 --- a/plugins/available/pack.plugin.bash +++ b/plugins/available/pack.plugin.bash @@ -3,619 +3,597 @@ cite about-plugin about-plugin 'CNB pack cli aliases' - -__pack_debug() -{ - if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then - echo "$*" >> "${BASH_COMP_DEBUG_FILE}" - fi +__pack_debug() { + if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then + echo "$*" >> "${BASH_COMP_DEBUG_FILE}" + fi } # Homebrew on Macs have version 1.3 of bash-completion which doesn't include # _init_completion. This is a very minimal version of that function. -__pack_init_completion() -{ - COMPREPLY=() - _get_comp_words_by_ref "$@" cur prev words cword +__pack_init_completion() { + COMPREPLY=() + _get_comp_words_by_ref "$@" cur prev words cword } -__pack_index_of_word() -{ - local w word=$1 - shift - index=0 - for w in "$@"; do - [[ $w = "$word" ]] && return - index=$((index+1)) - done - index=-1 +__pack_index_of_word() { + local w word=$1 + shift + index=0 + for w in "$@"; do + [[ $w = "$word" ]] && return + index=$((index + 1)) + done + index=-1 } -__pack_contains_word() -{ - local w word=$1; shift - for w in "$@"; do - [[ $w = "$word" ]] && return - done - return 1 +__pack_contains_word() { + local w word=$1 + shift + for w in "$@"; do + [[ $w = "$word" ]] && return + done + return 1 } -__pack_handle_reply() -{ - __pack_debug "${FUNCNAME[0]}" - case $cur in - -*) - if [[ $(type -t compopt) = "builtin" ]]; then - compopt -o nospace - fi - local allflags - if [ ${#must_have_one_flag[@]} -ne 0 ]; then - allflags=("${must_have_one_flag[@]}") - else - allflags=("${flags[*]} ${two_word_flags[*]}") - fi - COMPREPLY=( $(compgen -W "${allflags[*]}" -- "$cur") ) - if [[ $(type -t compopt) = "builtin" ]]; then - [[ "${COMPREPLY[0]}" == *= ]] || compopt +o nospace - fi - - # complete after --flag=abc - if [[ $cur == *=* ]]; then - if [[ $(type -t compopt) = "builtin" ]]; then - compopt +o nospace - fi - - local index flag - flag="${cur%=*}" - __pack_index_of_word "${flag}" "${flags_with_completion[@]}" - COMPREPLY=() - if [[ ${index} -ge 0 ]]; then - PREFIX="" - cur="${cur#*=}" - ${flags_completion[${index}]} - if [ -n "${ZSH_VERSION}" ]; then - # zsh completion needs --flag= prefix - eval "COMPREPLY=( \"\${COMPREPLY[@]/#/${flag}=}\" )" - fi - fi - fi - return 0; - ;; - esac - - # check if we are handling a flag with special work handling - local index - __pack_index_of_word "${prev}" "${flags_with_completion[@]}" - if [[ ${index} -ge 0 ]]; then - ${flags_completion[${index}]} - return - fi - - # we are parsing a flag and don't have a special handler, no completion - if [[ ${cur} != "${words[cword]}" ]]; then - return - fi - - local completions - completions=("${commands[@]}") - if [[ ${#must_have_one_noun[@]} -ne 0 ]]; then - completions=("${must_have_one_noun[@]}") - fi - if [[ ${#must_have_one_flag[@]} -ne 0 ]]; then - completions+=("${must_have_one_flag[@]}") - fi - COMPREPLY=( $(compgen -W "${completions[*]}" -- "$cur") ) - - if [[ ${#COMPREPLY[@]} -eq 0 && ${#noun_aliases[@]} -gt 0 && ${#must_have_one_noun[@]} -ne 0 ]]; then - COMPREPLY=( $(compgen -W "${noun_aliases[*]}" -- "$cur") ) - fi - - if [[ ${#COMPREPLY[@]} -eq 0 ]]; then - declare -F __custom_func >/dev/null && __custom_func - fi - - # available in bash-completion >= 2, not always present on macOS - if declare -F __ltrim_colon_completions >/dev/null; then - __ltrim_colon_completions "$cur" - fi - - # If there is only 1 completion and it is a flag with an = it will be completed - # but we don't want a space after the = - if [[ "${#COMPREPLY[@]}" -eq "1" ]] && [[ $(type -t compopt) = "builtin" ]] && [[ "${COMPREPLY[0]}" == --*= ]]; then - compopt -o nospace - fi +__pack_handle_reply() { + __pack_debug "${FUNCNAME[0]}" + case $cur in + -*) + if [[ $(type -t compopt) = "builtin" ]]; then + compopt -o nospace + fi + local allflags + if [ ${#must_have_one_flag[@]} -ne 0 ]; then + allflags=("${must_have_one_flag[@]}") + else + allflags=("${flags[*]} ${two_word_flags[*]}") + fi + COMPREPLY=($(compgen -W "${allflags[*]}" -- "$cur")) + if [[ $(type -t compopt) = "builtin" ]]; then + [[ "${COMPREPLY[0]}" == *= ]] || compopt +o nospace + fi + + # complete after --flag=abc + if [[ $cur == *=* ]]; then + if [[ $(type -t compopt) = "builtin" ]]; then + compopt +o nospace + fi + + local index flag + flag="${cur%=*}" + __pack_index_of_word "${flag}" "${flags_with_completion[@]}" + COMPREPLY=() + if [[ ${index} -ge 0 ]]; then + PREFIX="" + cur="${cur#*=}" + ${flags_completion[${index}]} + if [ -n "${ZSH_VERSION}" ]; then + # zsh completion needs --flag= prefix + eval "COMPREPLY=( \"\${COMPREPLY[@]/#/${flag}=}\" )" + fi + fi + fi + return 0 + ;; + esac + + # check if we are handling a flag with special work handling + local index + __pack_index_of_word "${prev}" "${flags_with_completion[@]}" + if [[ ${index} -ge 0 ]]; then + ${flags_completion[${index}]} + return + fi + + # we are parsing a flag and don't have a special handler, no completion + if [[ ${cur} != "${words[cword]}" ]]; then + return + fi + + local completions + completions=("${commands[@]}") + if [[ ${#must_have_one_noun[@]} -ne 0 ]]; then + completions=("${must_have_one_noun[@]}") + fi + if [[ ${#must_have_one_flag[@]} -ne 0 ]]; then + completions+=("${must_have_one_flag[@]}") + fi + COMPREPLY=($(compgen -W "${completions[*]}" -- "$cur")) + + if [[ ${#COMPREPLY[@]} -eq 0 && ${#noun_aliases[@]} -gt 0 && ${#must_have_one_noun[@]} -ne 0 ]]; then + COMPREPLY=($(compgen -W "${noun_aliases[*]}" -- "$cur")) + fi + + if [[ ${#COMPREPLY[@]} -eq 0 ]]; then + declare -F __custom_func > /dev/null && __custom_func + fi + + # available in bash-completion >= 2, not always present on macOS + if declare -F __ltrim_colon_completions > /dev/null; then + __ltrim_colon_completions "$cur" + fi + + # If there is only 1 completion and it is a flag with an = it will be completed + # but we don't want a space after the = + if [[ "${#COMPREPLY[@]}" -eq "1" ]] && [[ $(type -t compopt) = "builtin" ]] && [[ "${COMPREPLY[0]}" == --*= ]]; then + compopt -o nospace + fi } # The arguments should be in the form "ext1|ext2|extn" -__pack_handle_filename_extension_flag() -{ - local ext="$1" - _filedir "@(${ext})" +__pack_handle_filename_extension_flag() { + local ext="$1" + _filedir "@(${ext})" } -__pack_handle_subdirs_in_dir_flag() -{ - local dir="$1" - pushd "${dir}" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1 +__pack_handle_subdirs_in_dir_flag() { + local dir="$1" + pushd "${dir}" > /dev/null 2>&1 && _filedir -d && popd > /dev/null 2>&1 } -__pack_handle_flag() -{ - __pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" - - # if a command required a flag, and we found it, unset must_have_one_flag() - local flagname=${words[c]} - local flagvalue - # if the word contained an = - if [[ ${words[c]} == *"="* ]]; then - flagvalue=${flagname#*=} # take in as flagvalue after the = - flagname=${flagname%=*} # strip everything after the = - flagname="${flagname}=" # but put the = back - fi - __pack_debug "${FUNCNAME[0]}: looking for ${flagname}" - if __pack_contains_word "${flagname}" "${must_have_one_flag[@]}"; then - must_have_one_flag=() - fi - - # if you set a flag which only applies to this command, don't show subcommands - if __pack_contains_word "${flagname}" "${local_nonpersistent_flags[@]}"; then - commands=() - fi - - # keep flag value with flagname as flaghash - # flaghash variable is an associative array which is only supported in bash > 3. - if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then - if [ -n "${flagvalue}" ] ; then - flaghash[${flagname}]=${flagvalue} - elif [ -n "${words[ $((c+1)) ]}" ] ; then - flaghash[${flagname}]=${words[ $((c+1)) ]} - else - flaghash[${flagname}]="true" # pad "true" for bool flag - fi - fi - - # skip the argument to a two word flag - if __pack_contains_word "${words[c]}" "${two_word_flags[@]}"; then - c=$((c+1)) - # if we are looking for a flags value, don't show commands - if [[ $c -eq $cword ]]; then - commands=() - fi - fi - - c=$((c+1)) +__pack_handle_flag() { + __pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" + + # if a command required a flag, and we found it, unset must_have_one_flag() + local flagname=${words[c]} + local flagvalue + # if the word contained an = + if [[ ${words[c]} == *"="* ]]; then + flagvalue=${flagname#*=} # take in as flagvalue after the = + flagname=${flagname%=*} # strip everything after the = + flagname="${flagname}=" # but put the = back + fi + __pack_debug "${FUNCNAME[0]}: looking for ${flagname}" + if __pack_contains_word "${flagname}" "${must_have_one_flag[@]}"; then + must_have_one_flag=() + fi + + # if you set a flag which only applies to this command, don't show subcommands + if __pack_contains_word "${flagname}" "${local_nonpersistent_flags[@]}"; then + commands=() + fi + + # keep flag value with flagname as flaghash + # flaghash variable is an associative array which is only supported in bash > 3. + if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then + if [ -n "${flagvalue}" ]; then + flaghash[${flagname}]=${flagvalue} + elif [ -n "${words[$((c + 1))]}" ]; then + flaghash[${flagname}]=${words[$((c + 1))]} + else + flaghash[${flagname}]="true" # pad "true" for bool flag + fi + fi + + # skip the argument to a two word flag + if __pack_contains_word "${words[c]}" "${two_word_flags[@]}"; then + c=$((c + 1)) + # if we are looking for a flags value, don't show commands + if [[ $c -eq $cword ]]; then + commands=() + fi + fi + + c=$((c + 1)) } -__pack_handle_noun() -{ - __pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" +__pack_handle_noun() { + __pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" - if __pack_contains_word "${words[c]}" "${must_have_one_noun[@]}"; then - must_have_one_noun=() - elif __pack_contains_word "${words[c]}" "${noun_aliases[@]}"; then - must_have_one_noun=() - fi + if __pack_contains_word "${words[c]}" "${must_have_one_noun[@]}"; then + must_have_one_noun=() + elif __pack_contains_word "${words[c]}" "${noun_aliases[@]}"; then + must_have_one_noun=() + fi - nouns+=("${words[c]}") - c=$((c+1)) + nouns+=("${words[c]}") + c=$((c + 1)) } -__pack_handle_command() -{ - __pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" - - local next_command - if [[ -n ${last_command} ]]; then - next_command="_${last_command}_${words[c]//:/__}" - else - if [[ $c -eq 0 ]]; then - next_command="_pack_root_command" - else - next_command="_${words[c]//:/__}" - fi - fi - c=$((c+1)) - __pack_debug "${FUNCNAME[0]}: looking for ${next_command}" - declare -F "$next_command" >/dev/null && $next_command +__pack_handle_command() { + __pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" + + local next_command + if [[ -n ${last_command} ]]; then + next_command="_${last_command}_${words[c]//:/__}" + else + if [[ $c -eq 0 ]]; then + next_command="_pack_root_command" + else + next_command="_${words[c]//:/__}" + fi + fi + c=$((c + 1)) + __pack_debug "${FUNCNAME[0]}: looking for ${next_command}" + declare -F "$next_command" > /dev/null && $next_command } -__pack_handle_word() -{ - if [[ $c -ge $cword ]]; then - __pack_handle_reply - return - fi - __pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" - if [[ "${words[c]}" == -* ]]; then - __pack_handle_flag - elif __pack_contains_word "${words[c]}" "${commands[@]}"; then - __pack_handle_command - elif [[ $c -eq 0 ]]; then - __pack_handle_command - elif __pack_contains_word "${words[c]}" "${command_aliases[@]}"; then - # aliashash variable is an associative array which is only supported in bash > 3. - if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then - words[c]=${aliashash[${words[c]}]} - __pack_handle_command - else - __pack_handle_noun - fi - else - __pack_handle_noun - fi - __pack_handle_word +__pack_handle_word() { + if [[ $c -ge $cword ]]; then + __pack_handle_reply + return + fi + __pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" + if [[ "${words[c]}" == -* ]]; then + __pack_handle_flag + elif __pack_contains_word "${words[c]}" "${commands[@]}"; then + __pack_handle_command + elif [[ $c -eq 0 ]]; then + __pack_handle_command + elif __pack_contains_word "${words[c]}" "${command_aliases[@]}"; then + # aliashash variable is an associative array which is only supported in bash > 3. + if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then + words[c]=${aliashash[${words[c]}]} + __pack_handle_command + else + __pack_handle_noun + fi + else + __pack_handle_noun + fi + __pack_handle_word } -_pack_build() -{ - last_command="pack_build" - - command_aliases=() - - commands=() - - flags=() - two_word_flags=() - local_nonpersistent_flags=() - flags_with_completion=() - flags_completion=() - - flags+=("--builder=") - local_nonpersistent_flags+=("--builder=") - flags+=("--buildpack=") - local_nonpersistent_flags+=("--buildpack=") - flags+=("--clear-cache") - local_nonpersistent_flags+=("--clear-cache") - flags+=("--env=") - two_word_flags+=("-e") - local_nonpersistent_flags+=("--env=") - flags+=("--env-file=") - local_nonpersistent_flags+=("--env-file=") - flags+=("--help") - flags+=("-h") - local_nonpersistent_flags+=("--help") - flags+=("--no-pull") - local_nonpersistent_flags+=("--no-pull") - flags+=("--path=") - two_word_flags+=("-p") - local_nonpersistent_flags+=("--path=") - flags+=("--publish") - local_nonpersistent_flags+=("--publish") - flags+=("--run-image=") - local_nonpersistent_flags+=("--run-image=") - flags+=("--no-color") - flags+=("--quiet") - flags+=("-q") - flags+=("--timestamps") - - must_have_one_flag=() - must_have_one_noun=() - noun_aliases=() +_pack_build() { + last_command="pack_build" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--builder=") + local_nonpersistent_flags+=("--builder=") + flags+=("--buildpack=") + local_nonpersistent_flags+=("--buildpack=") + flags+=("--clear-cache") + local_nonpersistent_flags+=("--clear-cache") + flags+=("--env=") + two_word_flags+=("-e") + local_nonpersistent_flags+=("--env=") + flags+=("--env-file=") + local_nonpersistent_flags+=("--env-file=") + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + flags+=("--no-pull") + local_nonpersistent_flags+=("--no-pull") + flags+=("--path=") + two_word_flags+=("-p") + local_nonpersistent_flags+=("--path=") + flags+=("--publish") + local_nonpersistent_flags+=("--publish") + flags+=("--run-image=") + local_nonpersistent_flags+=("--run-image=") + flags+=("--no-color") + flags+=("--quiet") + flags+=("-q") + flags+=("--timestamps") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() } -_pack_run() -{ - last_command="pack_run" - - command_aliases=() - - commands=() - - flags=() - two_word_flags=() - local_nonpersistent_flags=() - flags_with_completion=() - flags_completion=() - - flags+=("--builder=") - local_nonpersistent_flags+=("--builder=") - flags+=("--buildpack=") - local_nonpersistent_flags+=("--buildpack=") - flags+=("--clear-cache") - local_nonpersistent_flags+=("--clear-cache") - flags+=("--env=") - two_word_flags+=("-e") - local_nonpersistent_flags+=("--env=") - flags+=("--env-file=") - local_nonpersistent_flags+=("--env-file=") - flags+=("--help") - flags+=("-h") - local_nonpersistent_flags+=("--help") - flags+=("--no-pull") - local_nonpersistent_flags+=("--no-pull") - flags+=("--path=") - two_word_flags+=("-p") - local_nonpersistent_flags+=("--path=") - flags+=("--port=") - local_nonpersistent_flags+=("--port=") - flags+=("--run-image=") - local_nonpersistent_flags+=("--run-image=") - flags+=("--no-color") - flags+=("--quiet") - flags+=("-q") - flags+=("--timestamps") - - must_have_one_flag=() - must_have_one_noun=() - noun_aliases=() +_pack_run() { + last_command="pack_run" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--builder=") + local_nonpersistent_flags+=("--builder=") + flags+=("--buildpack=") + local_nonpersistent_flags+=("--buildpack=") + flags+=("--clear-cache") + local_nonpersistent_flags+=("--clear-cache") + flags+=("--env=") + two_word_flags+=("-e") + local_nonpersistent_flags+=("--env=") + flags+=("--env-file=") + local_nonpersistent_flags+=("--env-file=") + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + flags+=("--no-pull") + local_nonpersistent_flags+=("--no-pull") + flags+=("--path=") + two_word_flags+=("-p") + local_nonpersistent_flags+=("--path=") + flags+=("--port=") + local_nonpersistent_flags+=("--port=") + flags+=("--run-image=") + local_nonpersistent_flags+=("--run-image=") + flags+=("--no-color") + flags+=("--quiet") + flags+=("-q") + flags+=("--timestamps") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() } -_pack_rebase() -{ - last_command="pack_rebase" - - command_aliases=() - - commands=() - - flags=() - two_word_flags=() - local_nonpersistent_flags=() - flags_with_completion=() - flags_completion=() - - flags+=("--help") - flags+=("-h") - local_nonpersistent_flags+=("--help") - flags+=("--no-pull") - local_nonpersistent_flags+=("--no-pull") - flags+=("--publish") - local_nonpersistent_flags+=("--publish") - flags+=("--run-image=") - local_nonpersistent_flags+=("--run-image=") - flags+=("--no-color") - flags+=("--quiet") - flags+=("-q") - flags+=("--timestamps") - - must_have_one_flag=() - must_have_one_noun=() - noun_aliases=() +_pack_rebase() { + last_command="pack_rebase" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + flags+=("--no-pull") + local_nonpersistent_flags+=("--no-pull") + flags+=("--publish") + local_nonpersistent_flags+=("--publish") + flags+=("--run-image=") + local_nonpersistent_flags+=("--run-image=") + flags+=("--no-color") + flags+=("--quiet") + flags+=("-q") + flags+=("--timestamps") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() } -_pack_create-builder() -{ - last_command="pack_create-builder" - - command_aliases=() - - commands=() - - flags=() - two_word_flags=() - local_nonpersistent_flags=() - flags_with_completion=() - flags_completion=() - - flags+=("--builder-config=") - two_word_flags+=("-b") - local_nonpersistent_flags+=("--builder-config=") - flags+=("--help") - flags+=("-h") - local_nonpersistent_flags+=("--help") - flags+=("--no-pull") - local_nonpersistent_flags+=("--no-pull") - flags+=("--publish") - local_nonpersistent_flags+=("--publish") - flags+=("--no-color") - flags+=("--quiet") - flags+=("-q") - flags+=("--timestamps") - - must_have_one_flag=() - must_have_one_flag+=("--builder-config=") - must_have_one_flag+=("-b") - must_have_one_noun=() - noun_aliases=() +_pack_create-builder() { + last_command="pack_create-builder" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--builder-config=") + two_word_flags+=("-b") + local_nonpersistent_flags+=("--builder-config=") + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + flags+=("--no-pull") + local_nonpersistent_flags+=("--no-pull") + flags+=("--publish") + local_nonpersistent_flags+=("--publish") + flags+=("--no-color") + flags+=("--quiet") + flags+=("-q") + flags+=("--timestamps") + + must_have_one_flag=() + must_have_one_flag+=("--builder-config=") + must_have_one_flag+=("-b") + must_have_one_noun=() + noun_aliases=() } -_pack_set-run-image-mirrors() -{ - last_command="pack_set-run-image-mirrors" - - command_aliases=() - - commands=() - - flags=() - two_word_flags=() - local_nonpersistent_flags=() - flags_with_completion=() - flags_completion=() - - flags+=("--help") - flags+=("-h") - local_nonpersistent_flags+=("--help") - flags+=("--mirror=") - two_word_flags+=("-m") - local_nonpersistent_flags+=("--mirror=") - flags+=("--no-color") - flags+=("--quiet") - flags+=("-q") - flags+=("--timestamps") - - must_have_one_flag=() - must_have_one_flag+=("--mirror=") - must_have_one_flag+=("-m") - must_have_one_noun=() - noun_aliases=() +_pack_set-run-image-mirrors() { + last_command="pack_set-run-image-mirrors" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + flags+=("--mirror=") + two_word_flags+=("-m") + local_nonpersistent_flags+=("--mirror=") + flags+=("--no-color") + flags+=("--quiet") + flags+=("-q") + flags+=("--timestamps") + + must_have_one_flag=() + must_have_one_flag+=("--mirror=") + must_have_one_flag+=("-m") + must_have_one_noun=() + noun_aliases=() } -_pack_inspect-builder() -{ - last_command="pack_inspect-builder" +_pack_inspect-builder() { + last_command="pack_inspect-builder" - command_aliases=() + command_aliases=() - commands=() + commands=() - flags=() - two_word_flags=() - local_nonpersistent_flags=() - flags_with_completion=() - flags_completion=() + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() - flags+=("--help") - flags+=("-h") - local_nonpersistent_flags+=("--help") - flags+=("--no-color") - flags+=("--quiet") - flags+=("-q") - flags+=("--timestamps") + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + flags+=("--no-color") + flags+=("--quiet") + flags+=("-q") + flags+=("--timestamps") - must_have_one_flag=() - must_have_one_noun=() - noun_aliases=() + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() } -_pack_set-default-builder() -{ - last_command="pack_set-default-builder" +_pack_set-default-builder() { + last_command="pack_set-default-builder" - command_aliases=() + command_aliases=() - commands=() + commands=() - flags=() - two_word_flags=() - local_nonpersistent_flags=() - flags_with_completion=() - flags_completion=() + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() - flags+=("--help") - flags+=("-h") - local_nonpersistent_flags+=("--help") - flags+=("--no-color") - flags+=("--quiet") - flags+=("-q") - flags+=("--timestamps") + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + flags+=("--no-color") + flags+=("--quiet") + flags+=("-q") + flags+=("--timestamps") - must_have_one_flag=() - must_have_one_noun=() - noun_aliases=() + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() } -_pack_version() -{ - last_command="pack_version" +_pack_version() { + last_command="pack_version" - command_aliases=() + command_aliases=() - commands=() + commands=() - flags=() - two_word_flags=() - local_nonpersistent_flags=() - flags_with_completion=() - flags_completion=() + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() - flags+=("--help") - flags+=("-h") - local_nonpersistent_flags+=("--help") - flags+=("--no-color") - flags+=("--quiet") - flags+=("-q") - flags+=("--timestamps") + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + flags+=("--no-color") + flags+=("--quiet") + flags+=("-q") + flags+=("--timestamps") - must_have_one_flag=() - must_have_one_noun=() - noun_aliases=() + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() } -_pack_completion() -{ - last_command="pack_completion" +_pack_completion() { + last_command="pack_completion" - command_aliases=() + command_aliases=() - commands=() + commands=() - flags=() - two_word_flags=() - local_nonpersistent_flags=() - flags_with_completion=() - flags_completion=() + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() - flags+=("--help") - flags+=("-h") - local_nonpersistent_flags+=("--help") - flags+=("--no-color") - flags+=("--quiet") - flags+=("-q") - flags+=("--timestamps") + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + flags+=("--no-color") + flags+=("--quiet") + flags+=("-q") + flags+=("--timestamps") - must_have_one_flag=() - must_have_one_noun=() - noun_aliases=() + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() } -_pack_root_command() -{ - last_command="pack" - - command_aliases=() - - commands=() - commands+=("build") - commands+=("run") - commands+=("rebase") - commands+=("create-builder") - commands+=("set-run-image-mirrors") - commands+=("inspect-builder") - commands+=("set-default-builder") - commands+=("version") - commands+=("completion") - - flags=() - two_word_flags=() - local_nonpersistent_flags=() - flags_with_completion=() - flags_completion=() - - flags+=("--help") - flags+=("-h") - local_nonpersistent_flags+=("--help") - flags+=("--no-color") - flags+=("--quiet") - flags+=("-q") - flags+=("--timestamps") - - must_have_one_flag=() - must_have_one_noun=() - noun_aliases=() +_pack_root_command() { + last_command="pack" + + command_aliases=() + + commands=() + commands+=("build") + commands+=("run") + commands+=("rebase") + commands+=("create-builder") + commands+=("set-run-image-mirrors") + commands+=("inspect-builder") + commands+=("set-default-builder") + commands+=("version") + commands+=("completion") + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + flags+=("--no-color") + flags+=("--quiet") + flags+=("-q") + flags+=("--timestamps") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() } -__start_pack() -{ - local cur prev words cword - declare -A flaghash 2>/dev/null || : - declare -A aliashash 2>/dev/null || : - if declare -F _init_completion >/dev/null 2>&1; then - _init_completion -s || return - else - __pack_init_completion -n "=" || return - fi - - local c=0 - local flags=() - local two_word_flags=() - local local_nonpersistent_flags=() - local flags_with_completion=() - local flags_completion=() - local commands=("pack") - local must_have_one_flag=() - local must_have_one_noun=() - local last_command - local nouns=() - - __pack_handle_word +__start_pack() { + local cur prev words cword + declare -A flaghash 2> /dev/null || : + declare -A aliashash 2> /dev/null || : + if declare -F _init_completion > /dev/null 2>&1; then + _init_completion -s || return + else + __pack_init_completion -n "=" || return + fi + + local c=0 + local flags=() + local two_word_flags=() + local local_nonpersistent_flags=() + local flags_with_completion=() + local flags_completion=() + local commands=("pack") + local must_have_one_flag=() + local must_have_one_noun=() + local last_command + local nouns=() + + __pack_handle_word } if [[ $(type -t compopt) = "builtin" ]]; then - complete -o default -F __start_pack pack + complete -o default -F __start_pack pack else - complete -o default -o nospace -F __start_pack pack + complete -o default -o nospace -F __start_pack pack fi # ex: ts=4 sw=4 et filetype=sh diff --git a/plugins/available/pipsi.plugin.bash b/plugins/available/pipsi.plugin.bash index 916d86d2af..bf42758c4d 100644 --- a/plugins/available/pipsi.plugin.bash +++ b/plugins/available/pipsi.plugin.bash @@ -1,7 +1,6 @@ cite about-plugin about-plugin 'load pipsi, if you are using it' -if [[ -f "$HOME/.local/bin/pipsi" ]] -then - pathmunge ~/.local/bin +if [[ -f "$HOME/.local/bin/pipsi" ]]; then + pathmunge ~/.local/bin fi diff --git a/plugins/available/postgres.plugin.bash b/plugins/available/postgres.plugin.bash index 9f66152b5c..ff24b0bbf7 100644 --- a/plugins/available/postgres.plugin.bash +++ b/plugins/available/postgres.plugin.bash @@ -2,82 +2,71 @@ cite about-plugin about-plugin 'postgres helper functions' - -export PGVERSION=`pg_config --version | awk '{print $2}'` -export POSTGRES_BIN=`pg_config --bindir` +export PGVERSION=$(pg_config --version | awk '{print $2}') +export POSTGRES_BIN=$(pg_config --bindir) COMMON_PGDATA_PATHS=("/usr/local/var/postgres" "/var/pgsql" "/Library/Server/PostgreSQL/Data") -for possible in "${COMMON_PGDATA_PATHS[@]}" -do - : - if [ -f "$possible/pg_hba.conf" ] - then - # echo "PGDATA: $possible" - export PGDATA=$possible - fi +for possible in "${COMMON_PGDATA_PATHS[@]}"; do + : + if [ -f "$possible/pg_hba.conf" ]; then + # echo "PGDATA: $possible" + export PGDATA=$possible + fi done - - - - function postgres_start { - about 'Starts PostgreSQL server' - group 'postgres' + about 'Starts PostgreSQL server' + group 'postgres' - echo 'Starting Postgres....'; - $POSTGRES_BIN/pg_ctl -D $PGDATA -l $PGDATA/logfile start + echo 'Starting Postgres....' + $POSTGRES_BIN/pg_ctl -D $PGDATA -l $PGDATA/logfile start } function postgres_stop { - about 'Stops PostgreSQL server' - group 'postgres' + about 'Stops PostgreSQL server' + group 'postgres' - echo 'Stopping Postgres....'; - $POSTGRES_BIN/pg_ctl -D $PGDATA -l $PGDATA/logfile stop -s -m fast + echo 'Stopping Postgres....' + $POSTGRES_BIN/pg_ctl -D $PGDATA -l $PGDATA/logfile stop -s -m fast } function postgres_status { - about 'Returns status of PostgreSQL server' - group 'postgres' - - # $POSTGRES_BIN/pg_ctl -D $PGDATA status - if [[ $(is_postgres_running) == "no server running" ]] - then - echo "Postgres service [STOPPED]" - else - echo "Postgres service [RUNNING]" - fi + about 'Returns status of PostgreSQL server' + group 'postgres' + + # $POSTGRES_BIN/pg_ctl -D $PGDATA status + if [[ $(is_postgres_running) == "no server running" ]]; then + echo "Postgres service [STOPPED]" + else + echo "Postgres service [RUNNING]" + fi } - function is_postgres_running { - $POSTGRES_BIN/pg_ctl -D $PGDATA status | grep -F -o "no server running" + $POSTGRES_BIN/pg_ctl -D $PGDATA status | grep -F -o "no server running" } - function postgres_restart { - about 'Restarts status of PostgreSQL server' - group 'postgres' + about 'Restarts status of PostgreSQL server' + group 'postgres' - echo 'Restarting Postgres....'; - $POSTGRES_BIN/pg_ctl -D $PGDATA restart + echo 'Restarting Postgres....' + $POSTGRES_BIN/pg_ctl -D $PGDATA restart } function postgres_logfile { - about 'View the last 500 lines from logfile' - group 'postgres' + about 'View the last 500 lines from logfile' + group 'postgres' - tail -500 $PGDATA/logfile | less + tail -500 $PGDATA/logfile | less } function postgres_serverlog { - about 'View the last 500 lines from server.log' - group 'postgres' + about 'View the last 500 lines from server.log' + group 'postgres' - tail -500 $PGDATA/server.log | less + tail -500 $PGDATA/server.log | less } - # function postgres_syslog { # about 'View the last 500 lines from syslog' # group 'postgres' diff --git a/plugins/available/rails.plugin.bash b/plugins/available/rails.plugin.bash index 414fd9f9b1..303264eef8 100644 --- a/plugins/available/rails.plugin.bash +++ b/plugins/available/rails.plugin.bash @@ -3,16 +3,16 @@ about-plugin 'Helper functions for Ruby on Rails' # Quick function to kill a daemonized Rails server function killrails() { - about 'Searches for a daemonized Rails server in tmp/pids and attempts to kill it.' - group 'rails' + about 'Searches for a daemonized Rails server in tmp/pids and attempts to kill it.' + group 'rails' - railsPid="$(cat tmp/pids/server.pid)" - if [ ! -z "$railsPid" ]; then - echo "[OK] Rails Server Process Id : ${railsPid}" - kill -9 $railsPid - echo "[OK] Process Killed" - else - echo "[FAIL] Error killing Rails server" - return 1 - fi + railsPid="$(cat tmp/pids/server.pid)" + if [ ! -z "$railsPid" ]; then + echo "[OK] Rails Server Process Id : ${railsPid}" + kill -9 $railsPid + echo "[OK] Process Killed" + else + echo "[FAIL] Error killing Rails server" + return 1 + fi } diff --git a/plugins/available/rvm.plugin.bash b/plugins/available/rvm.plugin.bash index ac2598efd4..c77bf40bc9 100644 --- a/plugins/available/rvm.plugin.bash +++ b/plugins/available/rvm.plugin.bash @@ -7,25 +7,24 @@ about-plugin 'load rvm, if you are using it' # Check to make sure that RVM is actually loaded before adding # the customizations to it. -if [ "$rvm_path" ] -then - # Load the auto-completion script if RVM was loaded. - [[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion +if [ "$rvm_path" ]; then + # Load the auto-completion script if RVM was loaded. + [[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion - switch () { - rvm $1 - local v=$(rvm_version) - rvm wrapper $1 textmate - echo "Switch to Ruby version: "$v - } + switch() { + rvm $1 + local v=$(rvm_version) + rvm wrapper $1 textmate + echo "Switch to Ruby version: "$v + } - rvm_default () { - rvm --default $1 - rvm wrapper $1 textmate - } + rvm_default() { + rvm --default $1 + rvm wrapper $1 textmate + } - function rvm_version () { - ruby --version - } + function rvm_version() { + ruby --version + } fi diff --git a/plugins/available/ssh.plugin.bash b/plugins/available/ssh.plugin.bash index 6e082881d6..8f373079f8 100644 --- a/plugins/available/ssh.plugin.bash +++ b/plugins/available/ssh.plugin.bash @@ -2,28 +2,28 @@ cite about-plugin about-plugin 'ssh helper functions' function add_ssh() { - about 'add entry to ssh config' - param '1: host' - param '2: hostname' - param '3: user' - group 'ssh' + about 'add entry to ssh config' + param '1: host' + param '2: hostname' + param '3: user' + group 'ssh' - [[ $# -ne 3 ]] && echo "add_ssh host hostname user" && return 1 - [[ ! -d ~/.ssh ]] && mkdir -m 700 ~/.ssh - [[ ! -e ~/.ssh/config ]] && touch ~/.ssh/config && chmod 600 ~/.ssh/config - echo -en "\n\nHost $1\n HostName $2\n User $3\n ServerAliveInterval 30\n ServerAliveCountMax 120" >> ~/.ssh/config + [[ $# -ne 3 ]] && echo "add_ssh host hostname user" && return 1 + [[ ! -d ~/.ssh ]] && mkdir -m 700 ~/.ssh + [[ ! -e ~/.ssh/config ]] && touch ~/.ssh/config && chmod 600 ~/.ssh/config + echo -en "\n\nHost $1\n HostName $2\n User $3\n ServerAliveInterval 30\n ServerAliveCountMax 120" >> ~/.ssh/config } function sshlist() { - about 'list hosts defined in ssh config' - group 'ssh' + about 'list hosts defined in ssh config' + group 'ssh' - awk '$1 ~ /Host$/ {for (i=2; i<=NF; i++) print $i}' ~/.ssh/config + awk '$1 ~ /Host$/ {for (i=2; i<=NF; i++) print $i}' ~/.ssh/config } function ssh-add-all() { - about 'add all ssh private keys to agent' - group 'ssh' + about 'add all ssh private keys to agent' + group 'ssh' - grep -slR "PRIVATE" ~/.ssh | xargs ssh-add + grep -slR "PRIVATE" ~/.ssh | xargs ssh-add } diff --git a/plugins/available/sshagent.plugin.bash b/plugins/available/sshagent.plugin.bash index 42acfb519e..e8e4a57606 100644 --- a/plugins/available/sshagent.plugin.bash +++ b/plugins/available/sshagent.plugin.bash @@ -3,141 +3,139 @@ cite about-plugin about-plugin 'sshagent helper functions' function _get_sshagent_pid_from_env_file() { - local env_file="${1}" - [[ -r "${env_file}" ]] || { - echo ""; - return - } - tail -1 "${env_file}" \ - | cut -d' ' -f4 \ - | cut -d';' -f1 + local env_file="${1}" + [[ -r "${env_file}" ]] || { + echo "" + return + } + tail -1 "${env_file}" \ + | cut -d' ' -f4 \ + | cut -d';' -f1 } function _get_process_status_field() { - # uses /proc filesystem - local \ - pid \ - status_file \ - field - pid="${1}" - field="${2}" - status_file="/proc/${pid}/status" - if ! ([[ -d "${status_file%/*}" ]] \ - && [[ -r "${status_file}" ]]); then - echo ""; return; - fi - grep "${field}:" "${status_file}" \ - | cut -d':' -f2 \ - | sed -e 's/[[:space:]]\+//g' \ - | cut -d'(' -f1 + # uses /proc filesystem + local \ + pid \ + status_file \ + field + pid="${1}" + field="${2}" + status_file="/proc/${pid}/status" + if ! ([[ -d "${status_file%/*}" ]] \ + && [[ -r "${status_file}" ]]); then + echo "" + return + fi + grep "${field}:" "${status_file}" \ + | cut -d':' -f2 \ + | sed -e 's/[[:space:]]\+//g' \ + | cut -d'(' -f1 } function _is_item_in_list() { - local item - for item in "${@:1}"; do - if [[ "${item}" == "${1}" ]]; then - return 1 - fi - done - return 0 + local item + for item in "${@:1}"; do + if [[ "${item}" == "${1}" ]]; then + return 1 + fi + done + return 0 } - function _is_proc_alive_at_pid() { - local \ - pid \ - expected_name \ - actual_name \ - actual_state - pid="${1?}" - expected_name="ssh-agent" - # we want to exclude: X (killed), T (traced), Z (zombie) - actual_name=$(_get_process_status_field "${pid}" "Name") - [[ "${expected_name}" == "${actual_name}" ]] || return 1 - actual_state=$(_get_process_status_field "${pid}" "State") - if _is_item_in_list "${actual_state}" "X" "T" "Z"; then - return 1 - fi - return 0 + local \ + pid \ + expected_name \ + actual_name \ + actual_state + pid="${1?}" + expected_name="ssh-agent" + # we want to exclude: X (killed), T (traced), Z (zombie) + actual_name=$(_get_process_status_field "${pid}" "Name") + [[ "${expected_name}" == "${actual_name}" ]] || return 1 + actual_state=$(_get_process_status_field "${pid}" "State") + if _is_item_in_list "${actual_state}" "X" "T" "Z"; then + return 1 + fi + return 0 } - function _ensure_valid_sshagent_env() { - local \ - agent_pid \ - tmp_res - - mkdir -p "${HOME}/.ssh" - type restorecon &> /dev/null - tmp_res="$?" - - if [[ "${tmp_res}" -eq 0 ]]; then - restorecon -rv "${HOME}/.ssh" - fi - - # no env file -> shoot a new agent - if ! [[ -r "${SSH_AGENT_ENV}" ]]; then - ssh-agent > "${SSH_AGENT_ENV}" - return - fi - - ## do not trust pre-existing SSH_AGENT_ENV - agent_pid=$(_get_sshagent_pid_from_env_file "${SSH_AGENT_ENV}") - if [[ -z "${agent_pid}" ]]; then - # no pid detected -> shoot a new agent - ssh-agent > "${SSH_AGENT_ENV}" - return - fi - - ## do not trust SSH_AGENT_PID - if _is_proc_alive_at_pid "${agent_pid}"; then - return - fi - - ssh-agent > "${SSH_AGENT_ENV}" - return + local \ + agent_pid \ + tmp_res + + mkdir -p "${HOME}/.ssh" + type restorecon &> /dev/null + tmp_res="$?" + + if [[ "${tmp_res}" -eq 0 ]]; then + restorecon -rv "${HOME}/.ssh" + fi + + # no env file -> shoot a new agent + if ! [[ -r "${SSH_AGENT_ENV}" ]]; then + ssh-agent > "${SSH_AGENT_ENV}" + return + fi + + ## do not trust pre-existing SSH_AGENT_ENV + agent_pid=$(_get_sshagent_pid_from_env_file "${SSH_AGENT_ENV}") + if [[ -z "${agent_pid}" ]]; then + # no pid detected -> shoot a new agent + ssh-agent > "${SSH_AGENT_ENV}" + return + fi + + ## do not trust SSH_AGENT_PID + if _is_proc_alive_at_pid "${agent_pid}"; then + return + fi + + ssh-agent > "${SSH_AGENT_ENV}" + return } - function _ensure_sshagent_dead() { - [[ -r "${SSH_AGENT_ENV}" ]] \ - || return ## no agent file - no problems - ## ensure the file indeed points to a really running agent: - agent_pid=$( - _get_sshagent_pid_from_env_file \ - "${SSH_AGENT_ENV}" - ) - - [[ -n "${agent_pid}" ]] \ - || return # no pid - no problem - - _is_proc_alive_at_pid "${agent_pid}" \ - || return # process is not alive - no problem - - echo -e -n "Killing ssh-agent (pid:${agent_pid}) ... " - kill -9 "${agent_pid}" && echo "DONE" || echo "FAILED" - rm -f "${SSH_AGENT_ENV}" + [[ -r "${SSH_AGENT_ENV}" ]] \ + || return ## no agent file - no problems + ## ensure the file indeed points to a really running agent: + agent_pid=$( + _get_sshagent_pid_from_env_file \ + "${SSH_AGENT_ENV}" + ) + + [[ -n "${agent_pid}" ]] \ + || return # no pid - no problem + + _is_proc_alive_at_pid "${agent_pid}" \ + || return # process is not alive - no problem + + echo -e -n "Killing ssh-agent (pid:${agent_pid}) ... " + kill -9 "${agent_pid}" && echo "DONE" || echo "FAILED" + rm -f "${SSH_AGENT_ENV}" } - function sshagent() { - about 'ensures ssh-agent is up and running' - param '1: on|off ' - example '$ sshagent on' - group 'ssh' - [[ -z "${SSH_AGENT_ENV}" ]] \ - && export SSH_AGENT_ENV="${HOME}/.ssh/agent_env.${HOSTNAME}" - - case "${1}" in - on) _ensure_valid_sshagent_env; - # shellcheck disable=SC1090 - source "${SSH_AGENT_ENV}" > /dev/null; - ;; - off) _ensure_sshagent_dead - ;; - *) - ;; - esac + about 'ensures ssh-agent is up and running' + param '1: on|off ' + example '$ sshagent on' + group 'ssh' + [[ -z "${SSH_AGENT_ENV}" ]] \ + && export SSH_AGENT_ENV="${HOME}/.ssh/agent_env.${HOSTNAME}" + + case "${1}" in + on) + _ensure_valid_sshagent_env + # shellcheck disable=SC1090 + source "${SSH_AGENT_ENV}" > /dev/null + ;; + off) + _ensure_sshagent_dead + ;; + *) ;; + esac } sshagent on diff --git a/plugins/available/subversion.plugin.bash b/plugins/available/subversion.plugin.bash index bdb3edf10c..28bf65f760 100644 --- a/plugins/available/subversion.plugin.bash +++ b/plugins/available/subversion.plugin.bash @@ -1,21 +1,21 @@ cite about-plugin about-plugin 'svn helper functions' -rm_svn(){ - about 'remove ".svn" files from directory' - param '1: directory to search for files' - group 'svn' +rm_svn() { + about 'remove ".svn" files from directory' + param '1: directory to search for files' + group 'svn' - if [ -z "$1" ]; then - reference rm_svn - return - fi - find $1 -name .svn -print0 | xargs -0 rm -rf + if [ -z "$1" ]; then + reference rm_svn + return + fi + find $1 -name .svn -print0 | xargs -0 rm -rf } -svn_add(){ - about 'add to svn repo' - group 'svn' +svn_add() { + about 'add to svn repo' + group 'svn' - svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add + svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add } diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index 4b90990489..c331dd8964 100755 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -2,8 +2,8 @@ # If not running interactively, don't do anything case $- in - *i*) ;; - *) return;; + *i*) ;; + *) return ;; esac # Path to the bash it configuration diff --git a/themes/codeword/codeword.theme.bash b/themes/codeword/codeword.theme.bash index d52403c12e..0966d6212d 100644 --- a/themes/codeword/codeword.theme.bash +++ b/themes/codeword/codeword.theme.bash @@ -6,19 +6,19 @@ SCM_THEME_PROMPT_CLEAN="${bold_green?} ✓${normal?}" SCM_GIT_CHAR="${green?}±${normal?}" function mark_prompt() { - echo "${green?}\$${normal?}" + echo "${green?}\$${normal?}" } function user_host_path_prompt() { - ps_user="${green?}\u${normal?}"; - ps_host="${blue?}\H${normal?}"; - ps_path="${yellow?}\w${normal?}"; - echo "${ps_user?}@${ps_host?}:${ps_path?}" + ps_user="${green?}\u${normal?}" + ps_host="${blue?}\H${normal?}" + ps_path="${yellow?}\w${normal?}" + echo "${ps_user?}@${ps_host?}:${ps_path?}" } function prompt() { - local SCM_PROMPT_FORMAT=' [%s%s]' - PS1="$(user_host_path_prompt)$(virtualenv_prompt)$(scm_prompt) $(mark_prompt) " + local SCM_PROMPT_FORMAT=' [%s%s]' + PS1="$(user_host_path_prompt)$(virtualenv_prompt)$(scm_prompt) $(mark_prompt) " } safe_append_prompt_command '_save-and-reload-history 1' diff --git a/themes/cooperkid/cooperkid.theme.bash b/themes/cooperkid/cooperkid.theme.bash index 1ffb95aa4b..1b9c9c1163 100644 --- a/themes/cooperkid/cooperkid.theme.bash +++ b/themes/cooperkid/cooperkid.theme.bash @@ -13,27 +13,27 @@ GIT_SHA_PREFIX="${blue}" GIT_SHA_SUFFIX="${reset_color}" function rvm_version_prompt { - if which rvm &> /dev/null; then - rvm=$(rvm-prompt) || return - if [ -n "$rvm" ]; then - echo -e "$rvm" - fi - fi + if which rvm &> /dev/null; then + rvm=$(rvm-prompt) || return + if [ -n "$rvm" ]; then + echo -e "$rvm" + fi + fi } function git_short_sha() { - SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$GIT_SHA_PREFIX$SHA$GIT_SHA_SUFFIX" + SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$GIT_SHA_PREFIX$SHA$GIT_SHA_SUFFIX" } function prompt() { - local return_status="" - local ruby="${red}$(ruby_version_prompt)${reset_color}" - local user_host="${green}\h @ \w${reset_color}" - local git_branch="$(git_short_sha)${cyan}$(scm_prompt_info)${reset_color}" - local prompt_symbol=' ' - local prompt_char="${purple}>_${reset_color} " + local return_status="" + local ruby="${red}$(ruby_version_prompt)${reset_color}" + local user_host="${green}\h @ \w${reset_color}" + local git_branch="$(git_short_sha)${cyan}$(scm_prompt_info)${reset_color}" + local prompt_symbol=' ' + local prompt_char="${purple}>_${reset_color} " - PS1="\n${user_host}${prompt_symbol}${ruby} ${git_branch} ${return_status}\n${prompt_char}" + PS1="\n${user_host}${prompt_symbol}${ruby} ${git_branch} ${return_status}\n${prompt_char}" } safe_append_prompt_command prompt diff --git a/themes/cupcake/cupcake.theme.bash b/themes/cupcake/cupcake.theme.bash index 889f3e68b4..f1b9b3c95b 100644 --- a/themes/cupcake/cupcake.theme.bash +++ b/themes/cupcake/cupcake.theme.bash @@ -51,28 +51,28 @@ icon_end="└❯ " # Display virtual environment info function virtualenv_prompt { - if [[ -n "$VIRTUAL_ENV" ]]; then - virtualenv=`basename "$VIRTUAL_ENV"` - echo -e "$VIRTUALENV_CHAR$virtualenv " - fi + if [[ -n "$VIRTUAL_ENV" ]]; then + virtualenv=$(basename "$VIRTUAL_ENV") + echo -e "$VIRTUALENV_CHAR$virtualenv " + fi } # Rename tab function tabname { - printf "\e]1;$1\a" + printf "\e]1;$1\a" } # Rename window function winname { - printf "\e]2;$1\a" + printf "\e]2;$1\a" } # PROMPT OUTPUT =============================================================== # Displays the current prompt function prompt_command() { - PS1="\n${icon_start}$(virtualenv_prompt)${icon_user}${bold_red}\u${normal}${icon_host}${bold_cyan}\h${normal}${icon_directory}${bold_purple}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} \")${white}$(scm_prompt_info)${normal}\n${icon_end}" - PS2="${icon_end}" + PS1="\n${icon_start}$(virtualenv_prompt)${icon_user}${bold_red}\u${normal}${icon_host}${bold_cyan}\h${normal}${icon_directory}${bold_purple}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} \")${white}$(scm_prompt_info)${normal}\n${icon_end}" + PS2="${icon_end}" } # Runs prompt (this bypasses bash_it $PROMPT setting) diff --git a/themes/demula/demula.theme.bash b/themes/demula/demula.theme.bash index 7d8d6cc8fe..f20e6097aa 100644 --- a/themes/demula/demula.theme.bash +++ b/themes/demula/demula.theme.bash @@ -47,60 +47,55 @@ D_VIMSHELL_COLOR="${cyan}" # ------------------------------------------------------------------ FUNCTIONS case $TERM in - xterm*) - TITLEBAR="\033]0;\w\007" - ;; - *) - TITLEBAR="" - ;; + xterm*) + TITLEBAR="\033]0;\w\007" + ;; + *) + TITLEBAR="" + ;; esac is_vim_shell() { - if [ ! -z "$VIMRUNTIME" ]; - then - echo "${D_INTERMEDIATE_COLOR}on ${D_VIMSHELL_COLOR}\ + if [ ! -z "$VIMRUNTIME" ]; then + echo "${D_INTERMEDIATE_COLOR}on ${D_VIMSHELL_COLOR}\ vim shell${D_DEFAULT_COLOR} " - fi + fi } mitsuhikos_lastcommandfailed() { - code=$? - if [ $code != 0 ]; - then - echo "${D_INTERMEDIATE_COLOR}exited ${D_CMDFAIL_COLOR}\ + code=$? + if [ $code != 0 ]; then + echo "${D_INTERMEDIATE_COLOR}exited ${D_CMDFAIL_COLOR}\ $code ${D_DEFAULT_COLOR}" - fi + fi } # vcprompt for scm instead of bash_it default demula_vcprompt() { - if [ ! -z "$VCPROMPT_EXECUTABLE" ]; - then - local D_VCPROMPT_FORMAT="on ${D_SCM_COLOR}%s${D_INTERMEDIATE_COLOR}:\ + if [ ! -z "$VCPROMPT_EXECUTABLE" ]; then + local D_VCPROMPT_FORMAT="on ${D_SCM_COLOR}%s${D_INTERMEDIATE_COLOR}:\ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}" - $VCPROMPT_EXECUTABLE -f "$D_VCPROMPT_FORMAT" - fi + $VCPROMPT_EXECUTABLE -f "$D_VCPROMPT_FORMAT" + fi } # checks if the plugin is installed before calling battery_charge safe_battery_charge() { - if _command_exists battery_charge ; - then - battery_charge - fi + if _command_exists battery_charge; then + battery_charge + fi } # -------------------------------------------------------------- PROMPT OUTPUT prompt() { - local LAST_COMMAND_FAILED=$(mitsuhikos_lastcommandfailed) - local SAVE_CURSOR='\033[s' - local RESTORE_CURSOR='\033[u' - local MOVE_CURSOR_RIGHTMOST='\033[500C' - local MOVE_CURSOR_5_LEFT='\033[5D' + local LAST_COMMAND_FAILED=$(mitsuhikos_lastcommandfailed) + local SAVE_CURSOR='\033[s' + local RESTORE_CURSOR='\033[u' + local MOVE_CURSOR_RIGHTMOST='\033[500C' + local MOVE_CURSOR_5_LEFT='\033[5D' - if [[ "$OSTYPE" = 'linux'* ]] - then - PS1="${TITLEBAR}${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT} + if [[ "$OSTYPE" = 'linux'* ]]; then + PS1="${TITLEBAR}${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT} $(safe_battery_charge)${RESTORE_CURSOR}\ ${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\ at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\ @@ -109,8 +104,8 @@ ${LAST_COMMAND_FAILED}\ $(demula_vcprompt)\ $(is_vim_shell) ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" - else - PS1="${TITLEBAR} + else + PS1="${TITLEBAR} ${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\ at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\ in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\ @@ -119,9 +114,9 @@ $(demula_vcprompt)\ $(is_vim_shell)\ $(safe_battery_charge) ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" - fi + fi - PS2="${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" + PS2="${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" } # Runs prompt (this bypasses bash_it $PROMPT setting) diff --git a/themes/doubletime/doubletime.theme.bash b/themes/doubletime/doubletime.theme.bash index 8186db736b..e60711aaf0 100644 --- a/themes/doubletime/doubletime.theme.bash +++ b/themes/doubletime/doubletime.theme.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2034,SC2154 SCM_THEME_PROMPT_DIRTY='' SCM_THEME_PROMPT_CLEAN='' @@ -7,35 +8,35 @@ SCM_SVN_CHAR="${bold_cyan}⑆${normal}" SCM_HG_CHAR="${bold_red}☿${normal}" SCM_THEME_PROMPT_PREFIX="" SCM_THEME_PROMPT_SUFFIX="" -if [ ! -z $RVM_THEME_PROMPT_COLOR ]; then - RVM_THEME_PROMPT_COLOR=$(eval echo $`echo ${RVM_THEME_PROMPT_COLOR}`); +if [[ -n "$RVM_THEME_PROMPT_COLOR" ]]; then + RVM_THEME_PROMPT_COLOR=$(eval "echo $$(echo ${RVM_THEME_PROMPT_COLOR})") else - RVM_THEME_PROMPT_COLOR="${red}" + RVM_THEME_PROMPT_COLOR="${red}" fi RVM_THEME_PROMPT_PREFIX="(${RVM_THEME_PROMPT_COLOR}rb${normal}: " RVM_THEME_PROMPT_SUFFIX=") " -if [ ! -z $VIRTUALENV_THEME_PROMPT_COLOR ]; then - VIRTUALENV_THEME_PROMPT_COLOR=$(eval echo $`echo ${VIRTUALENV_THEME_PROMPT_COLOR}`); +if [[ -n "$VIRTUALENV_THEME_PROMPT_COLOR" ]]; then + VIRTUALENV_THEME_PROMPT_COLOR=$(eval "echo $$(echo ${VIRTUALENV_THEME_PROMPT_COLOR})") else - VIRTUALENV_THEME_PROMPT_COLOR="${green}" + VIRTUALENV_THEME_PROMPT_COLOR="${green}" fi VIRTUALENV_THEME_PROMPT_PREFIX="(${VIRTUALENV_THEME_PROMPT_COLOR}py${normal}: " VIRTUALENV_THEME_PROMPT_SUFFIX=") " -if [ ! -z $THEME_PROMPT_HOST_COLOR ]; then - THEME_PROMPT_HOST_COLOR=$(eval echo $`echo ${THEME_PROMPT_HOST_COLOR}`); +if [[ -n "$THEME_PROMPT_HOST_COLOR" ]]; then + THEME_PROMPT_HOST_COLOR=$(eval "echo $$(echo ${THEME_PROMPT_HOST_COLOR})") else - THEME_PROMPT_HOST_COLOR="$blue" + THEME_PROMPT_HOST_COLOR="$blue" fi function prompt_setter() { - # Save history - _save-and-reload-history 1 - PS1=" + # Save history + _save-and-reload-history 1 + PS1=" $(clock_prompt) $(scm_char) [${THEME_PROMPT_HOST_COLOR}\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt)\w $(scm_prompt)$reset_color $ " - PS2='> ' - PS4='+ ' + PS2='> ' + PS4='+ ' } safe_append_prompt_command prompt_setter diff --git a/themes/doubletime_multiline/doubletime_multiline.theme.bash b/themes/doubletime_multiline/doubletime_multiline.theme.bash index f2dfe43a7b..bd6d7f0ddc 100644 --- a/themes/doubletime_multiline/doubletime_multiline.theme.bash +++ b/themes/doubletime_multiline/doubletime_multiline.theme.bash @@ -3,14 +3,14 @@ source "$BASH_IT/themes/doubletime/doubletime.theme.bash" function prompt_setter() { - # Save history - _save-and-reload-history 1 - PS1=" + # Save history + _save-and-reload-history 1 + PS1=" $(clock_prompt) $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt) \w $(scm_prompt)$reset_color $ " - PS2='> ' - PS4='+ ' + PS2='> ' + PS4='+ ' } safe_append_prompt_command prompt_setter diff --git a/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash b/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash index 0fe0eff486..4d1e493a19 100644 --- a/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash +++ b/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash @@ -3,14 +3,14 @@ source "$BASH_IT/themes/doubletime/doubletime.theme.bash" function prompt_setter() { - # Save history - _save-and-reload-history 1 - PS1=" + # Save history + _save-and-reload-history 1 + PS1=" $(clock_prompt) $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt) \w $(scm_prompt)$reset_color $ " - PS2='> ' - PS4='+ ' + PS2='> ' + PS4='+ ' } safe_append_prompt_command prompt_setter diff --git a/themes/dulcie/dulcie.theme.bash b/themes/dulcie/dulcie.theme.bash index f70c786491..cad0d22e7a 100755 --- a/themes/dulcie/dulcie.theme.bash +++ b/themes/dulcie/dulcie.theme.bash @@ -12,87 +12,87 @@ # # Configuration. Change these by adding them in your .bash_profile -DULCIE_COLOR=${DULCIE_COLOR:=1} # 0 = monochrome, 1 = colorful +DULCIE_COLOR=${DULCIE_COLOR:=1} # 0 = monochrome, 1 = colorful DULCIE_MULTILINE=${DULCIE_MULTILINE:=1} # 0 = Single line, 1 = SCM in separate line dulcie_color() { - echo -en "\[\e[38;5;${1}m\]" + echo -en "\[\e[38;5;${1}m\]" } dulcie_background() { - echo -en "\[\e[48;5;${1}m\]" + echo -en "\[\e[48;5;${1}m\]" } dulcie_prompt() { - color_user_root=$(dulcie_color 169) - color_user_nonroot="${green}" - color_host_local=$(dulcie_color 230) - color_host_remote=$(dulcie_color 214) - color_rootdir=$(dulcie_color 117) - color_workingdir=$(dulcie_color 117) - background_scm=$(dulcie_background 238) + color_user_root=$(dulcie_color 169) + color_user_nonroot="${green}" + color_host_local=$(dulcie_color 230) + color_host_remote=$(dulcie_color 214) + color_rootdir=$(dulcie_color 117) + color_workingdir=$(dulcie_color 117) + background_scm=$(dulcie_background 238) - SCM_THEME_ROOT_SUFFIX="|$(scm_char) " + SCM_THEME_ROOT_SUFFIX="|$(scm_char) " - # Set colors - if [ "${DULCIE_COLOR}" -eq "1" ]; then - if [[ $EUID -ne 0 ]]; then - color_user="${color_user_nonroot}" - else - color_user="${color_user_root}" - fi + # Set colors + if [ "${DULCIE_COLOR}" -eq "1" ]; then + if [[ $EUID -ne 0 ]]; then + color_user="${color_user_nonroot}" + else + color_user="${color_user_root}" + fi - if [[ -n "${SSH_CLIENT}" ]]; then - color_host="${color_host_remote}" - else - color_host="${color_host_local}" - fi + if [[ -n "${SSH_CLIENT}" ]]; then + color_host="${color_host_remote}" + else + color_host="${color_host_local}" + fi - DULCIE_USER="${color_user}\u${reset_color}" - DULCIE_HOST="${color_host}\h${reset_color}" - DULCIE_WORKINGDIR="${color_workingdir}\W${reset_color}" - DULCIE_PROMPTCHAR="${color_user}"'\$'"${reset_color}" + DULCIE_USER="${color_user}\u${reset_color}" + DULCIE_HOST="${color_host}\h${reset_color}" + DULCIE_WORKINGDIR="${color_workingdir}\W${reset_color}" + DULCIE_PROMPTCHAR="${color_user}"'\$'"${reset_color}" - SCM_THEME_PROMPT_DIRTY=" ${red}✗${reset_color}" - SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}" - DULCIE_SCM_BACKGROUND="${background_scm}" - DULCIE_SCM_DIR_COLOR="${color_rootdir}" - SCM_THEME_ROOT_SUFFIX="${reset_color}${SCM_THEME_ROOT_SUFFIX}" - SCM_THEME_PROMPT_DIRTY=" $(dulcie_color 1)✗${reset_color}" - SCM_THEME_PROMPT_CLEAN=" $(dulcie_color 10)✓${reset_color}" - else - DULCIE_USER='\u' - DULCIE_HOST='\h' - DULCIE_WORKINGDIR='\W' - DULCIE_PROMPTCHAR='\$' + SCM_THEME_PROMPT_DIRTY=" ${red}✗${reset_color}" + SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}" + DULCIE_SCM_BACKGROUND="${background_scm}" + DULCIE_SCM_DIR_COLOR="${color_rootdir}" + SCM_THEME_ROOT_SUFFIX="${reset_color}${SCM_THEME_ROOT_SUFFIX}" + SCM_THEME_PROMPT_DIRTY=" $(dulcie_color 1)✗${reset_color}" + SCM_THEME_PROMPT_CLEAN=" $(dulcie_color 10)✓${reset_color}" + else + DULCIE_USER='\u' + DULCIE_HOST='\h' + DULCIE_WORKINGDIR='\W' + DULCIE_PROMPTCHAR='\$' - DULCIE_SCM_BACKGROUND="" - DULCIE_SCM_DIR_COLOR="" - SCM_THEME_DIR_COLOR="" - SCM_THEME_PROMPT_DIRTY=" ✗" - SCM_THEME_PROMPT_CLEAN=" ✓" - fi + DULCIE_SCM_BACKGROUND="" + DULCIE_SCM_DIR_COLOR="" + SCM_THEME_DIR_COLOR="" + SCM_THEME_PROMPT_DIRTY=" ✗" + SCM_THEME_PROMPT_CLEAN=" ✓" + fi - # Change terminal title - printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}" + # Change terminal title + printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}" - # Open the new terminal in the same directory - _is_function __vte_osc7 && __vte_osc7 + # Open the new terminal in the same directory + _is_function __vte_osc7 && __vte_osc7 - PS1="${reset_color}[${DULCIE_USER}@${DULCIE_HOST}$(scm_prompt_info)${reset_color} ${DULCIE_WORKINGDIR}]" - if [[ "${DULCIE_MULTILINE}" -eq "1" ]]; then - PS1="${reset_color}[${DULCIE_USER}@${DULCIE_HOST}${reset_color} ${DULCIE_WORKINGDIR}]" - if [[ "$(scm_prompt_info)" ]]; then - SCM_THEME_PROMPT_PREFIX="${DULCIE_SCM_BACKGROUND}|${DULCIE_SCM_DIR_COLOR}" - SCM_THEME_PROMPT_SUFFIX="|${normal}" - PS1="$(scm_prompt_info)\n${PS1}" - fi - else - SCM_THEME_PROMPT_PREFIX=" ${DULCIE_SCM_BACKGROUND}|${DULCIE_SCM_DIR_COLOR}" - SCM_THEME_PROMPT_SUFFIX="|${normal}" - PS1="${reset_color}[${DULCIE_USER}@${DULCIE_HOST}$(scm_prompt_info)${reset_color} ${DULCIE_WORKINGDIR}]" - fi - PS1="${PS1}${DULCIE_PROMPTCHAR} " + PS1="${reset_color}[${DULCIE_USER}@${DULCIE_HOST}$(scm_prompt_info)${reset_color} ${DULCIE_WORKINGDIR}]" + if [[ "${DULCIE_MULTILINE}" -eq "1" ]]; then + PS1="${reset_color}[${DULCIE_USER}@${DULCIE_HOST}${reset_color} ${DULCIE_WORKINGDIR}]" + if [[ "$(scm_prompt_info)" ]]; then + SCM_THEME_PROMPT_PREFIX="${DULCIE_SCM_BACKGROUND}|${DULCIE_SCM_DIR_COLOR}" + SCM_THEME_PROMPT_SUFFIX="|${normal}" + PS1="$(scm_prompt_info)\n${PS1}" + fi + else + SCM_THEME_PROMPT_PREFIX=" ${DULCIE_SCM_BACKGROUND}|${DULCIE_SCM_DIR_COLOR}" + SCM_THEME_PROMPT_SUFFIX="|${normal}" + PS1="${reset_color}[${DULCIE_USER}@${DULCIE_HOST}$(scm_prompt_info)${reset_color} ${DULCIE_WORKINGDIR}]" + fi + PS1="${PS1}${DULCIE_PROMPTCHAR} " } safe_append_prompt_command dulcie_prompt diff --git a/themes/duru/duru.theme.bash b/themes/duru/duru.theme.bash index 69284100fd..a22bcf5f14 100644 --- a/themes/duru/duru.theme.bash +++ b/themes/duru/duru.theme.bash @@ -6,19 +6,18 @@ SCM_THEME_PROMPT_DIRTY=" ${red}with changes" SCM_THEME_PROMPT_CLEAN="" venv() { - if [ ! -z "$VIRTUAL_ENV" ] - then - local env=$VIRTUAL_ENV - echo "${gray} in ${orange}${env##*/} " - fi + if [ ! -z "$VIRTUAL_ENV" ]; then + local env=$VIRTUAL_ENV + echo "${gray} in ${orange}${env##*/} " + fi } last_two_dirs() { - pwd|rev|awk -F / '{print $1,$2}'|rev|sed s_\ _/_|sed "s|$(sed 's,\/,,'<<<$HOME)|~|g" + pwd | rev | awk -F / '{print $1,$2}' | rev | sed s_\ _/_ | sed "s|$(sed 's,\/,,' <<< $HOME)|~|g" } prompt() { - PS1="${yellow}# ${reset_color}$(last_two_dirs)$(scm_prompt_info)${reset_color}$(venv)${reset_color} ${cyan}\n> ${reset_color}" + PS1="${yellow}# ${reset_color}$(last_two_dirs)$(scm_prompt_info)${reset_color}$(venv)${reset_color} ${cyan}\n> ${reset_color}" } safe_append_prompt_command prompt diff --git a/themes/emperor/emperor.theme.bash b/themes/emperor/emperor.theme.bash index e3f2df8c9e..2f02eca78a 100644 --- a/themes/emperor/emperor.theme.bash +++ b/themes/emperor/emperor.theme.bash @@ -14,27 +14,27 @@ RVM_THEME_PROMPT_PREFIX="|" RVM_THEME_PROMPT_SUFFIX="|" function get_hour_color { - hour_color=$red - min=$(date +%M) - if [ "$min" -lt "15" ]; then - hour_color=$white - elif [ "$min" -lt "30" ]; then - hour_color=$green - elif [ "$min" -lt "45" ]; then - hour_color=$yellow - else - hour_color=$red - fi - echo "$hour_color" + hour_color=$red + min=$(date +%M) + if [ "$min" -lt "15" ]; then + hour_color=$white + elif [ "$min" -lt "30" ]; then + hour_color=$green + elif [ "$min" -lt "45" ]; then + hour_color=$yellow + else + hour_color=$red + fi + echo "$hour_color" } __emperor_clock() { - THEME_CLOCK_COLOR=$(get_hour_color) - clock_prompt + THEME_CLOCK_COLOR=$(get_hour_color) + clock_prompt } function prompt_command() { - PS1="\n$(__emperor_clock)${purple}\h ${reset_color}in ${prompt_color}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} " + PS1="\n$(__emperor_clock)${purple}\h ${reset_color}in ${prompt_color}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} " } THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H "} diff --git a/themes/envy/envy.theme.bash b/themes/envy/envy.theme.bash index f4f09be84c..ae28c1f622 100644 --- a/themes/envy/envy.theme.bash +++ b/themes/envy/envy.theme.bash @@ -13,7 +13,7 @@ VIRTUALENV_THEME_PROMPT_PREFIX="${green}ⓔ " VIRTUALENV_THEME_PROMPT_SUFFIX="" function prompt_command() { - PS1="\n$(virtualenv_prompt)${yellow}$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} " + PS1="\n$(virtualenv_prompt)${yellow}$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} " } safe_append_prompt_command prompt_command diff --git a/themes/font/font.theme.bash b/themes/font/font.theme.bash index 2dbccceadd..5af5e0e013 100644 --- a/themes/font/font.theme.bash +++ b/themes/font/font.theme.bash @@ -42,23 +42,23 @@ VIRTUALENV_THEME_PROMPT_PREFIX='(' VIRTUALENV_THEME_PROMPT_SUFFIX=') ' function prompt_command() { - # This needs to be first to save last command return code - local RC="$?" + # This needs to be first to save last command return code + local RC="$?" - hostname="${bold_black}\u@\h" - virtualenv="${white}$(virtualenv_prompt)" + hostname="${bold_black}\u@\h" + virtualenv="${white}$(virtualenv_prompt)" - # Set return status color - if [[ ${RC} == 0 ]]; then - ret_status="${bold_green}" - else - ret_status="${bold_red}" - fi + # Set return status color + if [[ ${RC} == 0 ]]; then + ret_status="${bold_green}" + else + ret_status="${bold_red}" + fi - # Append new history lines to history file - history -a + # Append new history lines to history file + history -a - PS1="$(clock_prompt)${virtualenv}$(user_host_prompt)${bold_cyan}\W $(scm_prompt_char_info)${ret_status}→ ${normal}" + PS1="$(clock_prompt)${virtualenv}$(user_host_prompt)${bold_cyan}\W $(scm_prompt_char_info)${ret_status}→ ${normal}" } safe_append_prompt_command prompt_command diff --git a/themes/gallifrey/gallifrey.theme.bash b/themes/gallifrey/gallifrey.theme.bash index 3ba48d71f5..cbffc78c46 100644 --- a/themes/gallifrey/gallifrey.theme.bash +++ b/themes/gallifrey/gallifrey.theme.bash @@ -16,18 +16,20 @@ SCM_HG_CHAR="${bold_red}☿${normal}" gallifrey_prompt() { SCM_PROMPT_FORMAT='%s%s' - ps_host="${green}\h${normal}"; - ps_user_mark="${bold}\$${normal}"; - ps_root_mark="${normal}§" - ps_path="${normal}\w"; + ps_host="${green}\h${normal}" + ps_user_mark="${bold}\$${normal}" + ps_root_mark="${normal}§" + ps_path="${normal}\w" - # make it work - case $(id -u) in - 0) PS1="$ps_host $ps_path $(scm_prompt)$ps_root_mark " - ;; - *) PS1="$ps_host $ps_path $(scm_prompt)$ps_user_mark " - ;; - esac + # make it work + case $(id -u) in + 0) + PS1="$ps_host $ps_path $(scm_prompt)$ps_root_mark " + ;; + *) + PS1="$ps_host $ps_path $(scm_prompt)$ps_user_mark " + ;; + esac } safe_append_prompt_command gallifrey_prompt diff --git a/themes/gitline/powerline.base.bash b/themes/gitline/powerline.base.bash index af31f27177..65b4751794 100644 --- a/themes/gitline/powerline.base.bash +++ b/themes/gitline/powerline.base.bash @@ -337,4 +337,9 @@ function __powerline_prompt_command() { fi PS1="${LEFT_PROMPT?}" + + ## cleanup ## + unset LAST_SEGMENT_COLOR \ + LEFT_PROMPT \ + SEGMENTS_AT_LEFT } diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index 404088d92d..6cba1553fd 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -84,117 +84,115 @@ IP_SEPARATOR=', ' # FUNCS ======================================================================= function get_ip_info { - myip=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+') - echo -e "$(ips | sed -e :a -e '$!N;s/\n/${IP_SEPARATOR}/;ta' | sed -e 's/127\.0\.0\.1\${IP_SEPARATOR}//g'), ${myip}" + myip=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+') + echo -e "$(ips | sed -e :a -e '$!N;s/\n/${IP_SEPARATOR}/;ta' | sed -e 's/127\.0\.0\.1\${IP_SEPARATOR}//g'), ${myip}" } # Displays ip prompt function ip_prompt_info() { - if [[ $IP_ENABLED == 1 ]]; then - echo -e " ${DEFAULT_COLOR}(${IP_COLOR}$(get_ip_info)${DEFAULT_COLOR})" - fi + if [[ $IP_ENABLED == 1 ]]; then + echo -e " ${DEFAULT_COLOR}(${IP_COLOR}$(get_ip_info)${DEFAULT_COLOR})" + fi } # Displays virtual info prompt (virtualenv/rvm) function virtual_prompt_info() { - local virtual_env_info=$(virtualenv_prompt) - local rvm_info=$(ruby_version_prompt) - local virtual_prompt="" + local virtual_env_info=$(virtualenv_prompt) + local rvm_info=$(ruby_version_prompt) + local virtual_prompt="" - local prefix=${VIRTUAL_THEME_PROMPT_PREFIX} - local suffix=${VIRTUAL_THEME_PROMPT_SUFFIX} + local prefix=${VIRTUAL_THEME_PROMPT_PREFIX} + local suffix=${VIRTUAL_THEME_PROMPT_SUFFIX} - # If no virtual info, just return - [[ -z "$virtual_env_info" && -z "$rvm_info" ]] && return + # If no virtual info, just return + [[ -z "$virtual_env_info" && -z "$rvm_info" ]] && return - # If virtual_env info present, append to prompt - [[ -n "$virtual_env_info" ]] && virtual_prompt="virtualenv: ${VE_COLOR}$virtual_env_info${DEFAULT_COLOR}" + # If virtual_env info present, append to prompt + [[ -n "$virtual_env_info" ]] && virtual_prompt="virtualenv: ${VE_COLOR}$virtual_env_info${DEFAULT_COLOR}" - if [[ -n "$rvm_info" ]] - then - [[ -n "$virtual_env_info" ]] && virtual_prompt="$virtual_prompt, " - virtual_prompt="${virtual_prompt}rvm: ${RVM_COLOR}$rvm_info${DEFAULT_COLOR}" - fi - echo -e "$prefix$virtual_prompt$suffix" + if [[ -n "$rvm_info" ]]; then + [[ -n "$virtual_env_info" ]] && virtual_prompt="$virtual_prompt, " + virtual_prompt="${virtual_prompt}rvm: ${RVM_COLOR}$rvm_info${DEFAULT_COLOR}" + fi + echo -e "$prefix$virtual_prompt$suffix" } # Parse git info function git_prompt_info() { - if [[ -n $(git status -s 2> /dev/null |grep -v ^# |grep -v "working directory clean") ]]; then - state=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} - else - state=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} - fi - prefix=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} - suffix=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} - ref=$(git symbolic-ref HEAD 2> /dev/null) || return - commit_id=$(git rev-parse HEAD 2>/dev/null) || return - - echo -e "$prefix${REF_COLOR}${ref#refs/heads/}${DEFAULT_COLOR}:${commit_id:0:$MAX_GIT_HEX_LENGTH}$state$suffix" + if [[ -n $(git status -s 2> /dev/null | grep -v ^# | grep -v "working directory clean") ]]; then + state=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + else + state=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + fi + prefix=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} + suffix=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} + ref=$(git symbolic-ref HEAD 2> /dev/null) || return + commit_id=$(git rev-parse HEAD 2> /dev/null) || return + + echo -e "$prefix${REF_COLOR}${ref#refs/heads/}${DEFAULT_COLOR}:${commit_id:0:$MAX_GIT_HEX_LENGTH}$state$suffix" } # Parse hg info function hg_prompt_info() { - if [[ -n $(hg status 2> /dev/null) ]]; then - state=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} - else - state=${HG_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} - fi - prefix=${HG_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} - suffix=${HG_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} - branch=$(hg summary 2> /dev/null | grep branch | awk '{print $2}') - changeset=$(hg summary 2> /dev/null | grep parent | awk '{print $2}') - - echo -e "$prefix${REF_COLOR}${branch}${DEFAULT_COLOR}:${changeset#*:}$state$suffix" + if [[ -n $(hg status 2> /dev/null) ]]; then + state=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + else + state=${HG_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + fi + prefix=${HG_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} + suffix=${HG_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} + branch=$(hg summary 2> /dev/null | grep branch | awk '{print $2}') + changeset=$(hg summary 2> /dev/null | grep parent | awk '{print $2}') + + echo -e "$prefix${REF_COLOR}${branch}${DEFAULT_COLOR}:${changeset#*:}$state$suffix" } # Parse svn info function svn_prompt_info() { - if [[ -n $(svn status --ignore-externals -q 2> /dev/null) ]]; then - state=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} - else - state=${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} - fi - prefix=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} - suffix=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} - ref=$(svn info 2> /dev/null | awk -F/ '/^URL:/ { for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return - [[ -z $ref ]] && return - - revision=$(svn info 2> /dev/null | sed -ne 's#^Revision: ##p' ) - - echo -e "$prefix${REF_COLOR}$ref${DEFAULT_COLOR}:$revision$state$suffix" + if [[ -n $(svn status --ignore-externals -q 2> /dev/null) ]]; then + state=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + else + state=${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + fi + prefix=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} + suffix=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} + ref=$(svn info 2> /dev/null | awk -F/ '/^URL:/ { for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return + [[ -z $ref ]] && return + + revision=$(svn info 2> /dev/null | sed -ne 's#^Revision: ##p') + + echo -e "$prefix${REF_COLOR}$ref${DEFAULT_COLOR}:$revision$state$suffix" } # Displays last X characters of pwd function limited_pwd() { - # Replace $HOME with ~ if possible - RELATIVE_PWD=${PWD/#$HOME/\~} + # Replace $HOME with ~ if possible + RELATIVE_PWD=${PWD/#$HOME/\~} - local offset=$((${#RELATIVE_PWD}-$MAX_PWD_LENGTH)) + local offset=$((${#RELATIVE_PWD} - $MAX_PWD_LENGTH)) - if [ $offset -gt "0" ] - then - local truncated_symbol="..." - TRUNCATED_PWD=${RELATIVE_PWD:$offset:$MAX_PWD_LENGTH} - echo -e "${truncated_symbol}/${TRUNCATED_PWD#*/}" - else - echo -e "${RELATIVE_PWD}" - fi + if [ $offset -gt "0" ]; then + local truncated_symbol="..." + TRUNCATED_PWD=${RELATIVE_PWD:$offset:$MAX_PWD_LENGTH} + echo -e "${truncated_symbol}/${TRUNCATED_PWD#*/}" + else + echo -e "${RELATIVE_PWD}" + fi } # Displays the current prompt function prompt() { - local UC=$USER_COLOR - [ $UID -eq "0" ] && UC=$SUPERUSER_COLOR - - if [[ $VIRTUAL_PROMPT_ENABLED == 1 ]]; then - PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h$(ip_prompt_info) ${DEFAULT_COLOR}in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(virtual_prompt_info)$(scm_prompt_info)${reset_color} \$ " - else - PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h$(ip_prompt_info) ${DEFAULT_COLOR}in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(scm_prompt_info)${reset_color} \$ " - fi - PS2='> ' - PS4='+ ' + local UC=$USER_COLOR + [ $UID -eq "0" ] && UC=$SUPERUSER_COLOR + + if [[ $VIRTUAL_PROMPT_ENABLED == 1 ]]; then + PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h$(ip_prompt_info) ${DEFAULT_COLOR}in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(virtual_prompt_info)$(scm_prompt_info)${reset_color} \$ " + else + PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h$(ip_prompt_info) ${DEFAULT_COLOR}in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(scm_prompt_info)${reset_color} \$ " + fi + PS2='> ' + PS4='+ ' } safe_append_prompt_command prompt diff --git a/themes/iterate/iterate.theme.bash b/themes/iterate/iterate.theme.bash index cf682a9f82..139d28c05c 100644 --- a/themes/iterate/iterate.theme.bash +++ b/themes/iterate/iterate.theme.bash @@ -28,32 +28,32 @@ RBFU_THEME_PROMPT_PREFIX="|" RBFU_THEME_PROMPT_SUFFIX="| " function rvm_version_prompt { - if which rvm &> /dev/null; then - rvm_current=$(rvm tools identifier) || return - rvm_default=$(rvm strings default) || return - [ "$rvm_current" != "$rvm_default" ] && ( echo -e "$RVM_THEME_PROMPT_PREFIX$rvm_current$RVM_THEME_PROMPT_SUFFIX" ) - fi + if which rvm &> /dev/null; then + rvm_current=$(rvm tools identifier) || return + rvm_default=$(rvm strings default) || return + [ "$rvm_current" != "$rvm_default" ] && (echo -e "$RVM_THEME_PROMPT_PREFIX$rvm_current$RVM_THEME_PROMPT_SUFFIX") + fi } function git_prompt_info { - git_prompt_vars - echo -e "$SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX" + git_prompt_vars + echo -e "$SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX" } LAST_PROMPT="" function prompt_command() { - local new_PS1="${bold_cyan}$(scm_char)${yellow}$(ruby_version_prompt)${green}\w $(scm_prompt_info)" - local new_prompt=$(PS1="$new_PS1" "$BASH" --norc -i &1 | sed -n '${s/^\(.*\)exit$/\1/p;}') - - if [ "$LAST_PROMPT" = "$new_prompt" ]; then - new_PS1="" - else - LAST_PROMPT="$new_prompt" - fi - - local wrap_char="" - [[ $COLUMNS && ${#new_PS1} > $(($COLUMNS/1)) ]] && wrap_char="\n" - PS1="${new_PS1}${green}${wrap_char}→${reset_color} " + local new_PS1="${bold_cyan}$(scm_char)${yellow}$(ruby_version_prompt)${green}\w $(scm_prompt_info)" + local new_prompt=$(PS1="$new_PS1" "$BASH" --norc -i < /dev/null 2>&1 | sed -n '${s/^\(.*\)exit$/\1/p;}') + + if [ "$LAST_PROMPT" = "$new_prompt" ]; then + new_PS1="" + else + LAST_PROMPT="$new_prompt" + fi + + local wrap_char="" + [[ $COLUMNS && ${#new_PS1} > $(($COLUMNS / 1)) ]] && wrap_char="\n" + PS1="${new_PS1}${green}${wrap_char}→${reset_color} " } safe_append_prompt_command prompt_command diff --git a/themes/kitsune/kitsune.theme.bash b/themes/kitsune/kitsune.theme.bash index c339f54c4e..3f767ddf42 100644 --- a/themes/kitsune/kitsune.theme.bash +++ b/themes/kitsune/kitsune.theme.bash @@ -16,13 +16,12 @@ case $TERM in TITLEBAR="" ;; esac -if [ "$?" == "0" ] -then - SC="${green}^_^"; +if [ "$?" == "0" ]; then + SC="${green}^_^" else - SC="${red}T_T"; + SC="${red}T_T" fi -BC=`battery_percentage` +BC=$(battery_percentage) function prompt_command() { #PS1="${TITLEBAR}[\u@\h \W $(scm_prompt_info)]\$ " PS1="\n${cyan}┌─${bold_white}[\u@\h]${cyan}─${bold_yellow}(\w)$(scm_prompt_info)\n${cyan}└─${bold_green}[\A]-${green}($BC%)${bold_cyan}-[${green}${bold_green}\$${bold_cyan}]${green} " @@ -34,5 +33,4 @@ SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" SCM_THEME_PROMPT_PREFIX="${bold_cyan}(" SCM_THEME_PROMPT_SUFFIX="${bold_cyan})${reset_color}" - safe_append_prompt_command prompt_command diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index 17458fd5f1..a9eb27663f 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -5,11 +5,11 @@ targetdir="$BASH_IT/themes/liquidprompt/liquidprompt" gray="\[\e[1;90m\]" cwd="$PWD" -if cd "$targetdir" &>/dev/null && git rev-parse --is-inside-work-tree &>/dev/null; then - true +if cd "$targetdir" &> /dev/null && git rev-parse --is-inside-work-tree &> /dev/null; then + true else - git clone https://github.com/nojhan/liquidprompt.git "$targetdir" && \ - echo -e "Successfully cloned liquidprompt!\n More configuration in '$targetdir/liquid.theme'." + git clone https://github.com/nojhan/liquidprompt.git "$targetdir" \ + && echo -e "Successfully cloned liquidprompt!\n More configuration in '$targetdir/liquid.theme'." fi cd "$cwd" @@ -29,63 +29,58 @@ export LP_PS1_PREFIX="┌─" export LP_PS1_POSTFIX="\n└▪ " export LP_ENABLE_RUNTIME=0 -_lp_legacy() -{ - type -t _lp_escape &> /dev/null +_lp_legacy() { + type -t _lp_escape &> /dev/null } -_lp_legacy && __lp_escape() -{ - ret="$(_lp_escape "$@")" +_lp_legacy && __lp_escape() { + ret="$(_lp_escape "$@")" } -_lp_git_branch() -{ - (( LP_ENABLE_GIT )) || return +_lp_git_branch() { + ((LP_ENABLE_GIT)) || return - \git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return + \git rev-parse --is-inside-work-tree > /dev/null 2>&1 || return - local commit branch ret + local commit branch ret - commit="$(\git rev-parse --short -q HEAD 2>/dev/null)" + commit="$(\git rev-parse --short -q HEAD 2> /dev/null)" - # Recent versions of Git support the --short option for symbolic-ref, but - # not 1.7.9 (Ubuntu 12.04) - if branch="$(\git symbolic-ref -q HEAD)"; then - __lp_escape "$commit:${branch#refs/heads/}" - lp_vcs_branch="$ret" - else - # In detached head state, use commit instead - # No escape needed - lp_vcs_branch="$commit" - fi - _lp_legacy && echo $lp_vcs_branch || return 0 + # Recent versions of Git support the --short option for symbolic-ref, but + # not 1.7.9 (Ubuntu 12.04) + if branch="$(\git symbolic-ref -q HEAD)"; then + __lp_escape "$commit:${branch#refs/heads/}" + lp_vcs_branch="$ret" + else + # In detached head state, use commit instead + # No escape needed + lp_vcs_branch="$commit" + fi + _lp_legacy && echo $lp_vcs_branch || return 0 } _lp_time() { - if (( LP_ENABLE_TIME )) && (( ! LP_TIME_ANALOG )); then - LP_TIME="${gray}$(date +%d-%H:%M)${normal}" - else - LP_TIME="" - fi + if ((LP_ENABLE_TIME)) && ((!LP_TIME_ANALOG)); then + LP_TIME="${gray}$(date +%d-%H:%M)${normal}" + else + LP_TIME="" + fi } # Implementation using lm-sensors -_lp_temp_sensors() -{ - local -i i - for i in $(sensors -u | - sed -n 's/^ temp[0-9][0-9]*_input: \([0-9]*\)\..*$/\1/p'); do - (( $i > ${temperature:-0} )) && (( $i != 127 )) && temperature=i - done +_lp_temp_sensors() { + local -i i + for i in $(sensors -u \ + | sed -n 's/^ temp[0-9][0-9]*_input: \([0-9]*\)\..*$/\1/p'); do + (($i > ${temperature:-0})) && (($i != 127)) && temperature=i + done } # Implementation using 'acpi -t' -_lp_temp_acpi() -{ - local -i i - for i in $(LANG=C acpi -t | - sed 's/.* \(-\?[0-9]*\)\.[0-9]* degrees C$/\1/p'); do - (( $i > ${temperature:-0} )) && (( $i != 127 )) && temperature=i - done +_lp_temp_acpi() { + local -i i + for i in $(LANG=C acpi -t \ + | sed 's/.* \(-\?[0-9]*\)\.[0-9]* degrees C$/\1/p'); do + (($i > ${temperature:-0})) && (($i != 127)) && temperature=i + done } diff --git a/themes/luan/luan.theme.bash b/themes/luan/luan.theme.bash index 8b7059e1c7..d5f0331f44 100644 --- a/themes/luan/luan.theme.bash +++ b/themes/luan/luan.theme.bash @@ -14,16 +14,16 @@ RVM_THEME_PROMPT_PREFIX="" RVM_THEME_PROMPT_SUFFIX="" function prompt_command() { - dtime="$(clock_prompt)" - user_host="${green}\u@${cyan}\h${normal}" - current_dir="${bold_blue}\w${normal}" - rvm_ruby="${bold_red}$(ruby_version_prompt)${normal}" - git_branch="$(scm_prompt_info)${normal}" - prompt="${bold_green}\$${normal} " - arrow="${bold_white}▶${normal} " - prompt="${bold_green}\$${normal} " + dtime="$(clock_prompt)" + user_host="${green}\u@${cyan}\h${normal}" + current_dir="${bold_blue}\w${normal}" + rvm_ruby="${bold_red}$(ruby_version_prompt)${normal}" + git_branch="$(scm_prompt_info)${normal}" + prompt="${bold_green}\$${normal} " + arrow="${bold_white}▶${normal} " + prompt="${bold_green}\$${normal} " - PS1="${dtime}${user_host}:${current_dir} ${rvm_ruby} ${git_branch} + PS1="${dtime}${user_host}:${current_dir} ${rvm_ruby} ${git_branch} $arrow $prompt" } diff --git a/themes/mairan/mairan.theme.bash b/themes/mairan/mairan.theme.bash index 89466ead07..65ef7ac1d3 100644 --- a/themes/mairan/mairan.theme.bash +++ b/themes/mairan/mairan.theme.bash @@ -1,29 +1,29 @@ # Mairan Bash Prompt, inspired by "Zork" if tput setaf 1 &> /dev/null; then - if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then - MAGENTA=$(tput setaf 9) - ORANGE=$(tput setaf 172) - GREEN=$(tput setaf 190) - PURPLE=$(tput setaf 141) - WHITE=$(tput setaf 0) - else - MAGENTA=$(tput setaf 5) - ORANGE=$(tput setaf 4) - GREEN=$(tput setaf 2) - PURPLE=$(tput setaf 1) - WHITE=$(tput setaf 7) - fi - BOLD=$(tput bold) - RESET=$(tput sgr0) + if [[ $(tput colors) -ge 256 ]] 2> /dev/null; then + MAGENTA=$(tput setaf 9) + ORANGE=$(tput setaf 172) + GREEN=$(tput setaf 190) + PURPLE=$(tput setaf 141) + WHITE=$(tput setaf 0) + else + MAGENTA=$(tput setaf 5) + ORANGE=$(tput setaf 4) + GREEN=$(tput setaf 2) + PURPLE=$(tput setaf 1) + WHITE=$(tput setaf 7) + fi + BOLD=$(tput bold) + RESET=$(tput sgr0) else - MAGENTA="\033[1;31m" - ORANGE="\033[1;33m" - GREEN="\033[1;32m" - PURPLE="\033[1;35m" - WHITE="\033[1;37m" - BOLD="" - RESET="\033[m" + MAGENTA="\033[1;31m" + ORANGE="\033[1;33m" + GREEN="\033[1;32m" + PURPLE="\033[1;35m" + WHITE="\033[1;37m" + BOLD="" + RESET="\033[m" fi # prompt_symbol='λ' @@ -44,77 +44,73 @@ SCM_HG_CHAR="${bold_red}☿${normal}" export MYSQL_PS1="(\u@\h) [\d]> " case $TERM in - xterm*) - TITLEBAR="\[\033]0;\w\007\]" - ;; - *) - TITLEBAR="" - ;; + xterm*) + TITLEBAR="\[\033]0;\w\007\]" + ;; + *) + TITLEBAR="" + ;; esac PS3=">> " __my_rvm_ruby_version() { - local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') - [ "$gemset" != "" ] && gemset="@$gemset" - local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') - local full="$version$gemset" - [ "$full" != "" ] && echo "[$full]" + local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') + [ "$gemset" != "" ] && gemset="@$gemset" + local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') + local full="$version$gemset" + [ "$full" != "" ] && echo "[$full]" } is_vim_shell() { - if [ ! -z "$VIMRUNTIME" ] - then - echo "[${cyan}vim shell${normal}]" - fi + if [ ! -z "$VIMRUNTIME" ]; then + echo "[${cyan}vim shell${normal}]" + fi } # show chroot if exist -chroot(){ - if [ -n "$debian_chroot" ] - then - my_ps_chroot="${bold_cyan}$debian_chroot${normal}"; - echo "($my_ps_chroot)"; - fi - } +chroot() { + if [ -n "$debian_chroot" ]; then + my_ps_chroot="${bold_cyan}$debian_chroot${normal}" + echo "($my_ps_chroot)" + fi +} # show virtualenvwrapper -my_ve(){ - if [ -n "$VIRTUAL_ENV" ] - then - my_ps_ve="${bold_purple}$ve${normal}"; - echo "($my_ps_ve)"; - fi - echo ""; - } +my_ve() { + if [ -n "$VIRTUAL_ENV" ]; then + my_ps_ve="${bold_purple}$ve${normal}" + echo "($my_ps_ve)" + fi + echo "" +} prompt() { SCM_PROMPT_FORMAT="[%s$GREEN%s]" - my_ps_host="$BOLD$ORANGE\h${normal}"; - # yes, these are the the same for now ... - my_ps_host_root="$ORANGE\h${normal}"; + my_ps_host="$BOLD$ORANGE\h${normal}" + # yes, these are the the same for now ... + my_ps_host_root="$ORANGE\h${normal}" - my_ps_user="$BOLD$GREEN\u${normal}" - my_ps_root="${bold_red}\u${normal}"; + my_ps_user="$BOLD$GREEN\u${normal}" + my_ps_root="${bold_red}\u${normal}" - if [ -n "$VIRTUAL_ENV" ] - then - ve=`basename "$VIRTUAL_ENV"`; - fi + if [ -n "$VIRTUAL_ENV" ]; then + ve=$(basename "$VIRTUAL_ENV") + fi - # nice prompt - case "`id -u`" in - 0) PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(scm_prompt)$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR} + # nice prompt + case "$(id -u)" in + 0) + PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(scm_prompt)$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR} └─▪ ${prompt_symbol} ${normal}" - ;; - *) PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(scm_prompt)${normal}$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR} + ;; + *) + PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(scm_prompt)${normal}$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR} └─▪ ${prompt_symbol} ${normal}" - ;; - esac + ;; + esac } PS2="└─▪ " - - safe_append_prompt_command prompt diff --git a/themes/mbriggs/mbriggs.theme.bash b/themes/mbriggs/mbriggs.theme.bash index 697fe0268f..9e1511e316 100644 --- a/themes/mbriggs/mbriggs.theme.bash +++ b/themes/mbriggs/mbriggs.theme.bash @@ -13,22 +13,22 @@ GIT_SHA_PREFIX=" ${yellow}" GIT_SHA_SUFFIX="${reset_color}" function git_short_sha() { - SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$GIT_SHA_PREFIX$SHA$GIT_SHA_SUFFIX" + SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$GIT_SHA_PREFIX$SHA$GIT_SHA_SUFFIX" } function prompt() { - local return_status="" - local ruby="${red}$(ruby_version_prompt)${reset_color}" - local user_host="${green}\h${reset_color}" - local current_path="\w" - local n_commands="\!" - local git_branch="$(git_short_sha)$(scm_prompt_info)" - local prompt_symbol='λ' - local open='(' - local close=')' - local prompt_char=' \$ ' + local return_status="" + local ruby="${red}$(ruby_version_prompt)${reset_color}" + local user_host="${green}\h${reset_color}" + local current_path="\w" + local n_commands="\!" + local git_branch="$(git_short_sha)$(scm_prompt_info)" + local prompt_symbol='λ' + local open='(' + local close=')' + local prompt_char=' \$ ' - PS1="\n${n_commands} ${user_host} ${prompt_symbol} ${ruby} ${open}${current_path}${git_branch}${close}${return_status}\n${prompt_char}" + PS1="\n${n_commands} ${user_host} ${prompt_symbol} ${ruby} ${open}${current_path}${git_branch}${close}${return_status}\n${prompt_char}" } safe_append_prompt_command prompt diff --git a/themes/metal/metal.theme.bash b/themes/metal/metal.theme.bash index e0eddd2685..e68a90a9b7 100644 --- a/themes/metal/metal.theme.bash +++ b/themes/metal/metal.theme.bash @@ -53,28 +53,28 @@ icon_end="└🤘-> " # Display virtual environment info function virtualenv_prompt { - if [[ -n "$VIRTUAL_ENV" ]]; then - virtualenv=`basename "$VIRTUAL_ENV"` - echo -e "$VIRTUALENV_CHAR$virtualenv " - fi + if [[ -n "$VIRTUAL_ENV" ]]; then + virtualenv=$(basename "$VIRTUAL_ENV") + echo -e "$VIRTUALENV_CHAR$virtualenv " + fi } # Rename tab function tabname { - printf "\e]1;$1\a" + printf "\e]1;$1\a" } # Rename window function winname { - printf "\e]2;$1\a" + printf "\e]2;$1\a" } # PROMPT OUTPUT =============================================================== # Displays the current prompt function prompt_command() { - PS1="\n${icon_start}$(virtualenv_prompt)${icon_user}${bold_green}\u${normal}${icon_host}${bold_cyan}\h${normal}${icon_directory}${bold_purple}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} \")${white}$(scm_prompt_info)${normal}\n${icon_end}" - PS2="${icon_end}" + PS1="\n${icon_start}$(virtualenv_prompt)${icon_user}${bold_green}\u${normal}${icon_host}${bold_cyan}\h${normal}${icon_directory}${bold_purple}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} \")${white}$(scm_prompt_info)${normal}\n${icon_end}" + PS2="${icon_end}" } # Runs prompt (this bypasses bash_it $PROMPT setting) diff --git a/themes/minimal/minimal.theme.bash b/themes/minimal/minimal.theme.bash index 72fb2200d8..2bf807c16f 100644 --- a/themes/minimal/minimal.theme.bash +++ b/themes/minimal/minimal.theme.bash @@ -6,7 +6,7 @@ SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${green}✓" prompt() { - PS1="$(scm_prompt_info)${reset_color} ${cyan}\W${reset_color} " + PS1="$(scm_prompt_info)${reset_color} ${cyan}\W${reset_color} " } safe_append_prompt_command prompt diff --git a/themes/modern-t/modern-t.theme.bash b/themes/modern-t/modern-t.theme.bash index 197f5a2345..c0a5b556e7 100644 --- a/themes/modern-t/modern-t.theme.bash +++ b/themes/modern-t/modern-t.theme.bash @@ -16,26 +16,24 @@ SCM_HG_CHAR="${bold_red}☿${normal}" case $TERM in xterm*) - TITLEBAR="\[\033]0;\w\007\]" - ;; + TITLEBAR="\[\033]0;\w\007\]" + ;; *) - TITLEBAR="" - ;; + TITLEBAR="" + ;; esac PS3=">> " is_vim_shell() { - if [ ! -z "$VIMRUNTIME" ] - then + if [ ! -z "$VIMRUNTIME" ]; then echo "[${cyan}vim shell${normal}]" fi } prompt() { SCM_PROMPT_FORMAT='[%s][%s]' - if [ $? -ne 0 ] - then + if [ $? -ne 0 ]; then # Yes, the indenting on these is weird, but it has to be like # this otherwise it won't display properly. @@ -49,6 +47,4 @@ ${bold_red}└─▪${normal} " PS2="└─▪ " - - safe_append_prompt_command prompt diff --git a/themes/modern-time/modern-time.theme.bash b/themes/modern-time/modern-time.theme.bash index fc8458fffe..ceb2f5ede3 100644 --- a/themes/modern-time/modern-time.theme.bash +++ b/themes/modern-time/modern-time.theme.bash @@ -12,18 +12,17 @@ SCM_HG_CHAR="${bold_red}☿${normal}" case $TERM in xterm*) - TITLEBAR="\[\033]0;\w\007\]" - ;; + TITLEBAR="\[\033]0;\w\007\]" + ;; *) - TITLEBAR="" - ;; + TITLEBAR="" + ;; esac PS3=">> " is_vim_shell() { - if [ ! -z "$VIMRUNTIME" ] - then + if [ ! -z "$VIMRUNTIME" ]; then echo "[${cyan}vim shell${normal}]" fi } @@ -34,8 +33,7 @@ modern_current_time_prompt() { prompt() { SCM_PROMPT_FORMAT='[%s][%s]' - if [ $? -ne 0 ] - then + if [ $? -ne 0 ]; then # Yes, the indenting on these is weird, but it has to be like # this otherwise it won't display properly. @@ -49,6 +47,4 @@ ${bold_red}└─▪${normal} " PS2="└─▪ " - - safe_append_prompt_command prompt diff --git a/themes/morris/morris.theme.bash b/themes/morris/morris.theme.bash index d6b0258dcf..58b1bad816 100644 --- a/themes/morris/morris.theme.bash +++ b/themes/morris/morris.theme.bash @@ -1,4 +1,3 @@ - # prompt theming # added TITLEBAR for updating the tab and window titles with the pwd @@ -24,5 +23,4 @@ SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" SCM_THEME_PROMPT_PREFIX="${green}(" SCM_THEME_PROMPT_SUFFIX="${green})${reset_color}" - safe_append_prompt_command prompt_command diff --git a/themes/n0qorg/n0qorg.theme.bash b/themes/n0qorg/n0qorg.theme.bash index 12952913cb..b82a17f3d4 100644 --- a/themes/n0qorg/n0qorg.theme.bash +++ b/themes/n0qorg/n0qorg.theme.bash @@ -6,7 +6,7 @@ # for example: # ananas ~/Code/bash-it/themes (master*)» function prompt_command() { - PS1="${bold_blue}[$(hostname)]${normal} \w${normal} ${bold_white}[$(git_prompt_info)]${normal}» " + PS1="${bold_blue}[$(hostname)]${normal} \w${normal} ${bold_white}[$(git_prompt_info)]${normal}» " } safe_append_prompt_command prompt_command diff --git a/themes/newin/newin.theme.bash b/themes/newin/newin.theme.bash index 9f54dc8a11..cabd024fe1 100644 --- a/themes/newin/newin.theme.bash +++ b/themes/newin/newin.theme.bash @@ -6,8 +6,8 @@ SCM_THEME_PROMPT_PREFIX=" ${purple}|${green} " SCM_THEME_PROMPT_SUFFIX="${purple} |" prompt() { - exit_code=$? - PS1="$(if [[ ${exit_code} = 0 ]]; then echo "${green}${exit_code}"; else echo "${red}${exit_code}"; fi) ${yellow}\t ${cyan}\w$(scm_prompt_info)${reset_color}\n${orange}$ ${reset_color}" + exit_code=$? + PS1="$(if [[ ${exit_code} = 0 ]]; then echo "${green}${exit_code}"; else echo "${red}${exit_code}"; fi) ${yellow}\t ${cyan}\w$(scm_prompt_info)${reset_color}\n${orange}$ ${reset_color}" } safe_append_prompt_command prompt diff --git a/themes/nwinkler/nwinkler.theme.bash b/themes/nwinkler/nwinkler.theme.bash index 983c8d0020..5bb66aee69 100644 --- a/themes/nwinkler/nwinkler.theme.bash +++ b/themes/nwinkler/nwinkler.theme.bash @@ -15,24 +15,25 @@ # The exit code functionality currently doesn't work if you are using the 'fasd' plugin, # since 'fasd' is messing with the $PROMPT_COMMAND - PROMPT_END_CLEAN="${green}→${reset_color}" PROMPT_END_DIRTY="${red}→${reset_color}" function prompt_end() { - echo -e "$PROMPT_END" + echo -e "$PROMPT_END" } prompt_setter() { - local exit_status=$? - if [[ $exit_status -eq 0 ]]; then PROMPT_END=$PROMPT_END_CLEAN - else PROMPT_END=$PROMPT_END_DIRTY - fi - # Save history - _save-and-reload-history 1 - PS1="($(clock_prompt)) $(scm_char) [${blue}\u${reset_color}@${green}\H${reset_color}] ${yellow}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " - PS2='> ' - PS4='+ ' + local exit_status=$? + if [[ $exit_status -eq 0 ]]; then + PROMPT_END=$PROMPT_END_CLEAN + else + PROMPT_END=$PROMPT_END_DIRTY + fi + # Save history + _save-and-reload-history 1 + PS1="($(clock_prompt)) $(scm_char) [${blue}\u${reset_color}@${green}\H${reset_color}] ${yellow}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " + PS2='> ' + PS4='+ ' } safe_append_prompt_command prompt_setter diff --git a/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash b/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash index 05391b0b7b..c23860a1b4 100644 --- a/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash +++ b/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash @@ -18,88 +18,89 @@ RANDOM_COLOR_FILE=$HOME/.nwinkler_random_colors function randomize_nwinkler { - declare -a AVAILABLE_COLORS + declare -a AVAILABLE_COLORS - AVAILABLE_COLORS=( - $black - $red - $green - $yellow - $blue - $purple - $cyan - $white - $orange - $bold_black - $bold_red - $bold_green - $bold_yellow - $bold_blue - $bold_purple - $bold_cyan - $bold_white - $bold_orange - ) - # Uncomment these to allow underlines: - #$underline_black - #$underline_red - #$underline_green - #$underline_yellow - #$underline_blue - #$underline_purple - #$underline_cyan - #$underline_white - #$underline_orange - #) + AVAILABLE_COLORS=( + $black + $red + $green + $yellow + $blue + $purple + $cyan + $white + $orange + $bold_black + $bold_red + $bold_green + $bold_yellow + $bold_blue + $bold_purple + $bold_cyan + $bold_white + $bold_orange + ) + # Uncomment these to allow underlines: + #$underline_black + #$underline_red + #$underline_green + #$underline_yellow + #$underline_blue + #$underline_purple + #$underline_cyan + #$underline_white + #$underline_orange + #) - USERNAME_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]} ]} - HOSTNAME_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]} ]} - TIME_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]} ]} - THEME_CLOCK_COLOR=$TIME_COLOR - PATH_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]} ]} + USERNAME_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]}]} + HOSTNAME_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]}]} + TIME_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]}]} + THEME_CLOCK_COLOR=$TIME_COLOR + PATH_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]}]} - echo "$USERNAME_COLOR,$HOSTNAME_COLOR,$TIME_COLOR,$PATH_COLOR," > $RANDOM_COLOR_FILE + echo "$USERNAME_COLOR,$HOSTNAME_COLOR,$TIME_COLOR,$PATH_COLOR," > $RANDOM_COLOR_FILE } -if [ -f $RANDOM_COLOR_FILE ]; -then - # read the colors already stored in the file - IFS=',' read -ra COLORS < $RANDOM_COLOR_FILE - USERNAME_COLOR=${COLORS[0]} - HOSTNAME_COLOR=${COLORS[1]} - TIME_COLOR=${COLORS[2]} - THEME_CLOCK_COLOR=$TIME_COLOR - PATH_COLOR=${COLORS[3]} +if [ -f $RANDOM_COLOR_FILE ]; then + # read the colors already stored in the file + IFS=',' read -ra COLORS < $RANDOM_COLOR_FILE + USERNAME_COLOR=${COLORS[0]} + HOSTNAME_COLOR=${COLORS[1]} + TIME_COLOR=${COLORS[2]} + THEME_CLOCK_COLOR=$TIME_COLOR + PATH_COLOR=${COLORS[3]} else - # No colors stored yet. Generate them! - randomize_nwinkler + # No colors stored yet. Generate them! + randomize_nwinkler - echo - echo "Looks like you are using the nwinkler_random_color bashit theme for the first time." - echo "Random colors have been generated to be used in your prompt." - echo "If you don't like them, run the command:" - echo " randomize_nwinkler" - echo "until you get a combination that you like." - echo + echo + echo "Looks like you are using the nwinkler_random_color bashit theme for the first time." + echo "Random colors have been generated to be used in your prompt." + echo "If you don't like them, run the command:" + echo " randomize_nwinkler" + echo "until you get a combination that you like." + echo fi PROMPT_END_CLEAN="${green}→${reset_color}" PROMPT_END_DIRTY="${red}→${reset_color}" function prompt_end() { - echo -e "$PROMPT_END" + echo -e "$PROMPT_END" } prompt_setter() { - local exit_status=$? - if [[ $exit_status -eq 0 ]]; then PROMPT_END=$PROMPT_END_CLEAN - else PROMPT_END=$PROMPT_END_DIRTY - fi - # Save history - _save-and-reload-history 1 - PS1="($(clock_prompt)${reset_color}) $(scm_char) [${USERNAME_COLOR}\u${reset_color}@${HOSTNAME_COLOR}\H${reset_color}] ${PATH_COLOR}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " - PS2='> ' - PS4='+ ' + local exit_status=$? + if [[ $exit_status -eq 0 ]]; then + PROMPT_END=$PROMPT_END_CLEAN + else + PROMPT_END=$PROMPT_END_DIRTY + fi + # Save history + _save-and-reload-history 1 + PS1="($(clock_prompt)${reset_color}) $(scm_char) [${USERNAME_COLOR}\u${reset_color}@${HOSTNAME_COLOR}\H${reset_color}] ${PATH_COLOR}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " + PS2='> ' + PS4='+ ' } safe_append_prompt_command prompt_setter diff --git a/themes/parrot/parrot.theme.bash b/themes/parrot/parrot.theme.bash index 251eb942f7..266fe8a683 100644 --- a/themes/parrot/parrot.theme.bash +++ b/themes/parrot/parrot.theme.bash @@ -1,37 +1,35 @@ - - # git branch parser function parse_git_branch() { - echo -e "\[\033[1;34m\]$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')\[\033[0m\]" + echo -e "\[\033[1;34m\]$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')\[\033[0m\]" } function parse_git_branch_no_color() { - echo -e "$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')" + echo -e "$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')" } function prompt() { - # If not running interactively, don't do anything - [[ $- != *i* ]] && return - - local force_color_prompt=yes - - if [ -n "$force_color_prompt" ]; then - if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then - # We have color support; assume it's compliant with Ecma-48 - # (ISO/IEC-6429). (Lack of such support is extremely rare, and such - # a case would tend to support setf rather than setaf.) - local color_prompt=yes - else - local color_prompt= - fi - fi - - if [ "$color_prompt" = yes ]; then - PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\")[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]root\[\033[01;33m\]@\[\033[01;96m\]\h'; else echo '\[\033[0;39m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h'; fi)\[\033[0;31m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]\[\e[01;33m\]$(parse_git_branch) $\[\e[0m\] " - - else - PS1='┌──[\u@\h]─[\w]\n└──╼ $(parse_git_branch_no_color) $ ' - fi + # If not running interactively, don't do anything + [[ $- != *i* ]] && return + + local force_color_prompt=yes + + if [ -n "$force_color_prompt" ]; then + if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then + # We have color support; assume it's compliant with Ecma-48 + # (ISO/IEC-6429). (Lack of such support is extremely rare, and such + # a case would tend to support setf rather than setaf.) + local color_prompt=yes + else + local color_prompt= + fi + fi + + if [ "$color_prompt" = yes ]; then + PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\")[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]root\[\033[01;33m\]@\[\033[01;96m\]\h'; else echo '\[\033[0;39m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h'; fi)\[\033[0;31m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]\[\e[01;33m\]$(parse_git_branch) $\[\e[0m\] " + + else + PS1='┌──[\u@\h]─[\w]\n└──╼ $(parse_git_branch_no_color) $ ' + fi } safe_append_prompt_command prompt diff --git a/themes/powerline-multiline/powerline-multiline.base.bash b/themes/powerline-multiline/powerline-multiline.base.bash index 0269c58c39..8270aa5bb3 100644 --- a/themes/powerline-multiline/powerline-multiline.base.bash +++ b/themes/powerline-multiline/powerline-multiline.base.bash @@ -1,106 +1,107 @@ . "$BASH_IT/themes/powerline/powerline.base.bash" function __powerline_last_status_prompt { - [[ "$1" -ne 0 ]] && echo "$(set_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${1} ${normal}" + [[ "$1" -ne 0 ]] && echo "$(set_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${1} ${normal}" } function __powerline_right_segment { - local OLD_IFS="${IFS}"; IFS="|" - local params=( $1 ) - IFS="${OLD_IFS}" - local padding=0 - local pad_before_segment=" " - - if [[ "${SEGMENTS_AT_RIGHT}" -eq 0 ]]; then - if [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -ne 0 ]]; then - pad_before_segment="" - fi - RIGHT_PROMPT+="$(set_color ${params[1]} -)${POWERLINE_RIGHT_END}${normal}" - (( padding += 1 )) - else - if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR}" -ne 0 ]]; then - pad_before_segment="" - fi - # Since the previous segment wasn't the last segment, add padding, if needed - # - if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR}" -eq 0 ]]; then - RIGHT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR}) ${normal}" - (( padding += 1 )) - fi - if [[ "${LAST_SEGMENT_COLOR}" -eq "${params[1]}" ]]; then - RIGHT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR})${POWERLINE_RIGHT_SEPARATOR_SOFT}${normal}" - else - RIGHT_PROMPT+="$(set_color ${params[1]} ${LAST_SEGMENT_COLOR})${POWERLINE_RIGHT_SEPARATOR}${normal}" - fi - (( padding += 1 )) - fi - - RIGHT_PROMPT+="$(set_color "${POWERLINE_PROMPT_FOREGROUND_COLOR}" ${params[1]})${pad_before_segment}${params[0]}${normal}" - - (( padding += ${#pad_before_segment} )) - (( padding += ${#params[0]} )) - - (( RIGHT_PROMPT_LENGTH += padding )) - LAST_SEGMENT_COLOR="${params[1]}" - (( SEGMENTS_AT_RIGHT += 1 )) + local OLD_IFS="${IFS}" + IFS="|" + local params=($1) + IFS="${OLD_IFS}" + local padding=0 + local pad_before_segment=" " + + if [[ "${SEGMENTS_AT_RIGHT}" -eq 0 ]]; then + if [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -ne 0 ]]; then + pad_before_segment="" + fi + RIGHT_PROMPT+="$(set_color ${params[1]} -)${POWERLINE_RIGHT_END}${normal}" + ((padding += 1)) + else + if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR}" -ne 0 ]]; then + pad_before_segment="" + fi + # Since the previous segment wasn't the last segment, add padding, if needed + # + if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR}" -eq 0 ]]; then + RIGHT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR}) ${normal}" + ((padding += 1)) + fi + if [[ "${LAST_SEGMENT_COLOR}" -eq "${params[1]}" ]]; then + RIGHT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR})${POWERLINE_RIGHT_SEPARATOR_SOFT}${normal}" + else + RIGHT_PROMPT+="$(set_color ${params[1]} ${LAST_SEGMENT_COLOR})${POWERLINE_RIGHT_SEPARATOR}${normal}" + fi + ((padding += 1)) + fi + + RIGHT_PROMPT+="$(set_color "${POWERLINE_PROMPT_FOREGROUND_COLOR}" ${params[1]})${pad_before_segment}${params[0]}${normal}" + + ((padding += ${#pad_before_segment})) + ((padding += ${#params[0]})) + + ((RIGHT_PROMPT_LENGTH += padding)) + LAST_SEGMENT_COLOR="${params[1]}" + ((SEGMENTS_AT_RIGHT += 1)) } function __powerline_right_first_segment_padding { - RIGHT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR}) ${normal}" - (( RIGHT_PROMPT_LENGTH += 1 )) + RIGHT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR}) ${normal}" + ((RIGHT_PROMPT_LENGTH += 1)) } function __powerline_prompt_command { - local last_status="$?" ## always the first - local move_cursor_rightmost='\033[500C' - - LEFT_PROMPT="" - RIGHT_PROMPT="" - RIGHT_PROMPT_LENGTH=${POWERLINE_PADDING} - SEGMENTS_AT_LEFT=0 - SEGMENTS_AT_RIGHT=0 - LAST_SEGMENT_COLOR="" - - _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" - - ## left prompt ## - for segment in $POWERLINE_LEFT_PROMPT; do - local info="$(__powerline_${segment}_prompt)" - [[ -n "${info}" ]] && __powerline_left_segment "${info}" - done - - if [[ -n "${LEFT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -eq 0 ]]; then - __powerline_left_last_segment_padding - fi - - [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -)${POWERLINE_LEFT_END}${normal}" - - ## right prompt ## - if [[ -n "${POWERLINE_RIGHT_PROMPT}" ]]; then - # LEFT_PROMPT+="${move_cursor_rightmost}" - for segment in $POWERLINE_RIGHT_PROMPT; do - local info="$(__powerline_${segment}_prompt)" - [[ -n "${info}" ]] && __powerline_right_segment "${info}" - done - - if [[ -n "${RIGHT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT}" -eq 0 ]]; then - __powerline_right_first_segment_padding - fi - - RIGHT_PAD=$(printf "%.s " $(seq 1 $RIGHT_PROMPT_LENGTH)) - LEFT_PROMPT+="${RIGHT_PAD}${move_cursor_rightmost}" - LEFT_PROMPT+="\033[$(( ${#RIGHT_PAD} - 1 ))D" - fi - - local prompt="${PROMPT_CHAR}" - if [[ "${POWERLINE_COMPACT_PROMPT}" -eq 0 ]]; then - prompt+=" " - fi - - PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n$(__powerline_last_status_prompt ${last_status})${prompt}" - - ## cleanup ## - unset LAST_SEGMENT_COLOR \ - LEFT_PROMPT RIGHT_PROMPT RIGHT_PROMPT_LENGTH \ - SEGMENTS_AT_LEFT SEGMENTS_AT_RIGHT + local last_status="$?" ## always the first + local move_cursor_rightmost='\033[500C' + + LEFT_PROMPT="" + RIGHT_PROMPT="" + RIGHT_PROMPT_LENGTH=${POWERLINE_PADDING} + SEGMENTS_AT_LEFT=0 + SEGMENTS_AT_RIGHT=0 + LAST_SEGMENT_COLOR="" + + _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" + + ## left prompt ## + for segment in $POWERLINE_LEFT_PROMPT; do + local info="$(__powerline_${segment}_prompt)" + [[ -n "${info}" ]] && __powerline_left_segment "${info}" + done + + if [[ -n "${LEFT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -eq 0 ]]; then + __powerline_left_last_segment_padding + fi + + [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -)${POWERLINE_LEFT_END}${normal}" + + ## right prompt ## + if [[ -n "${POWERLINE_RIGHT_PROMPT}" ]]; then + # LEFT_PROMPT+="${move_cursor_rightmost}" + for segment in $POWERLINE_RIGHT_PROMPT; do + local info="$(__powerline_${segment}_prompt)" + [[ -n "${info}" ]] && __powerline_right_segment "${info}" + done + + if [[ -n "${RIGHT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT}" -eq 0 ]]; then + __powerline_right_first_segment_padding + fi + + RIGHT_PAD=$(printf "%.s " $(seq 1 $RIGHT_PROMPT_LENGTH)) + LEFT_PROMPT+="${RIGHT_PAD}${move_cursor_rightmost}" + LEFT_PROMPT+="\033[$((${#RIGHT_PAD} - 1))D" + fi + + local prompt="${PROMPT_CHAR}" + if [[ "${POWERLINE_COMPACT_PROMPT}" -eq 0 ]]; then + prompt+=" " + fi + + PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n$(__powerline_last_status_prompt ${last_status})${prompt}" + + ## cleanup ## + unset LAST_SEGMENT_COLOR \ + LEFT_PROMPT RIGHT_PROMPT RIGHT_PROMPT_LENGTH \ + SEGMENTS_AT_LEFT SEGMENTS_AT_RIGHT } diff --git a/themes/powerline-naked/powerline-naked.base.bash b/themes/powerline-naked/powerline-naked.base.bash index dfc63f7640..6e3b21667c 100644 --- a/themes/powerline-naked/powerline-naked.base.bash +++ b/themes/powerline-naked/powerline-naked.base.bash @@ -1,35 +1,36 @@ . "$BASH_IT/themes/powerline/powerline.base.bash" function __powerline_left_segment { - local OLD_IFS="${IFS}"; IFS="|" - local params=( $1 ) - IFS="${OLD_IFS}" - local separator="" - local pad_before_segment=" " + local OLD_IFS="${IFS}" + IFS="|" + local params=($1) + IFS="${OLD_IFS}" + local separator="" + local pad_before_segment=" " - if [[ "${SEGMENTS_AT_LEFT}" -eq 0 ]]; then - if [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT}" -ne 0 ]]; then - pad_before_segment="" - fi - else - if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR}" -ne 0 ]]; then - pad_before_segment="" - fi - # Since the previous segment wasn't the last segment, add padding, if needed - # - if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR}" -eq 0 ]]; then - LEFT_PROMPT+=" " - fi - LEFT_PROMPT+="${POWERLINE_LEFT_SEPARATOR}" - fi + if [[ "${SEGMENTS_AT_LEFT}" -eq 0 ]]; then + if [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT}" -ne 0 ]]; then + pad_before_segment="" + fi + else + if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR}" -ne 0 ]]; then + pad_before_segment="" + fi + # Since the previous segment wasn't the last segment, add padding, if needed + # + if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR}" -eq 0 ]]; then + LEFT_PROMPT+=" " + fi + LEFT_PROMPT+="${POWERLINE_LEFT_SEPARATOR}" + fi - LEFT_PROMPT+="$(set_color ${params[1]} -)${pad_before_segment}${params[0]}${normal}" - LAST_SEGMENT_COLOR=${params[1]} - (( SEGMENTS_AT_LEFT += 1 )) + LEFT_PROMPT+="$(set_color ${params[1]} -)${pad_before_segment}${params[0]}${normal}" + LAST_SEGMENT_COLOR=${params[1]} + ((SEGMENTS_AT_LEFT += 1)) - _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" + _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" } function __powerline_left_last_segment_padding { - LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -) ${normal}" + LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -) ${normal}" } diff --git a/themes/powerline-plain/powerline-plain.base.bash b/themes/powerline-plain/powerline-plain.base.bash index ce91ef899c..c077a089fc 100644 --- a/themes/powerline-plain/powerline-plain.base.bash +++ b/themes/powerline-plain/powerline-plain.base.bash @@ -1,61 +1,62 @@ . "$BASH_IT/themes/powerline/powerline.base.bash" function __powerline_left_segment { - local OLD_IFS="${IFS}"; IFS="|" - local params=( $1 ) - IFS="${OLD_IFS}" - local pad_before_segment=" " - - if [[ "${SEGMENTS_AT_LEFT}" -eq 0 ]]; then - if [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT}" -ne 0 ]]; then - pad_before_segment="" - fi - else - if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR}" -ne 0 ]]; then - pad_before_segment="" - fi - # Since the previous segment wasn't the last segment, add padding, if needed - # - if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR}" -eq 0 ]]; then - LEFT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR}) ${normal}" - fi - fi - - LEFT_PROMPT+="$(set_color - ${params[1]})${pad_before_segment}${params[0]}${normal}" - LAST_SEGMENT_COLOR=${params[1]} - (( SEGMENTS_AT_LEFT += 1 )) + local OLD_IFS="${IFS}" + IFS="|" + local params=($1) + IFS="${OLD_IFS}" + local pad_before_segment=" " + + if [[ "${SEGMENTS_AT_LEFT}" -eq 0 ]]; then + if [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT}" -ne 0 ]]; then + pad_before_segment="" + fi + else + if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR}" -ne 0 ]]; then + pad_before_segment="" + fi + # Since the previous segment wasn't the last segment, add padding, if needed + # + if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR}" -eq 0 ]]; then + LEFT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR}) ${normal}" + fi + fi + + LEFT_PROMPT+="$(set_color - ${params[1]})${pad_before_segment}${params[0]}${normal}" + LAST_SEGMENT_COLOR=${params[1]} + ((SEGMENTS_AT_LEFT += 1)) } function __powerline_prompt_command { - local last_status="$?" ## always the first + local last_status="$?" ## always the first - LEFT_PROMPT="" - SEGMENTS_AT_LEFT=0 - LAST_SEGMENT_COLOR="" - PROMPT_AFTER="${POWERLINE_PROMPT_AFTER}" + LEFT_PROMPT="" + SEGMENTS_AT_LEFT=0 + LAST_SEGMENT_COLOR="" + PROMPT_AFTER="${POWERLINE_PROMPT_AFTER}" - _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" + _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" - ## left prompt ## - for segment in $POWERLINE_PROMPT; do - local info="$(__powerline_${segment}_prompt)" - [[ -n "${info}" ]] && __powerline_left_segment "${info}" - done + ## left prompt ## + for segment in $POWERLINE_PROMPT; do + local info="$(__powerline_${segment}_prompt)" + [[ -n "${info}" ]] && __powerline_left_segment "${info}" + done - [[ "${last_status}" -ne 0 ]] && __powerline_left_segment $(__powerline_last_status_prompt ${last_status}) + [[ "${last_status}" -ne 0 ]] && __powerline_left_segment $(__powerline_last_status_prompt ${last_status}) - if [[ -n "${LEFT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -eq 0 ]]; then - __powerline_left_last_segment_padding - fi + if [[ -n "${LEFT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -eq 0 ]]; then + __powerline_left_last_segment_padding + fi - if [[ "${POWERLINE_COMPACT_PROMPT}" -eq 0 ]]; then - LEFT_PROMPT+=" " - fi + if [[ "${POWERLINE_COMPACT_PROMPT}" -eq 0 ]]; then + LEFT_PROMPT+=" " + fi - PS1="${LEFT_PROMPT}${PROMPT_AFTER}" + PS1="${LEFT_PROMPT}${PROMPT_AFTER}" - ## cleanup ## - unset LAST_SEGMENT_COLOR \ - LEFT_PROMPT \ - SEGMENTS_AT_LEFT + ## cleanup ## + unset LAST_SEGMENT_COLOR \ + LEFT_PROMPT \ + SEGMENTS_AT_LEFT } diff --git a/themes/powerturk/powerturk.theme.bash b/themes/powerturk/powerturk.theme.bash index 3352f68006..85f2d7ae91 100644 --- a/themes/powerturk/powerturk.theme.bash +++ b/themes/powerturk/powerturk.theme.bash @@ -29,156 +29,155 @@ CWD_THEME_PROMPT_COLOR=240 LAST_STATUS_THEME_PROMPT_COLOR=52 _collapsed_wd() { - # echo -e "\u2771\u276d\u276f" - echo $(pwd | perl -pe " + # echo -e "\u2771\u276d\u276f" + echo $(pwd | perl -pe " BEGIN { binmode STDIN, ':encoding(UTF-8)'; binmode STDOUT, ':encoding(UTF-8)'; - }; s|^$HOME||g; s|/([^/])[^/]*(?=/)|/\$1|g") | \ - sed -re "s/\//  /g" + }; s|^$HOME||g; s|/([^/])[^/]*(?=/)|/\$1|g") \ + | sed -re "s/\//  /g" } -_swd(){ -# Adapted from http://stackoverflow.com/a/2951707/1766716 - begin="" # The unshortened beginning of the path. - shortbegin="" # The shortened beginning of the path. - current="" # The section of the path we're currently working on. - end="${2:-${PWD}}/" # The unmodified rest of the path. - - if [[ "$end" =~ "$HOME" ]]; then - INHOME=1 - end="${end#$HOME}" #strip /home/username from start of string - begin="$HOME" #start expansion from the right spot - else - INHOME=0 - fi - - end="${end#/}" # Strip the first / - shortenedpath="$end" # The whole path, to check the length. - maxlength="${1:-0}" - - shopt -q nullglob && NGV="-s" || NGV="-u" # Store the value for later. - shopt -s nullglob # Without this, anything that doesn't exist in the filesystem turns into */*/*/... - - while [[ "$end" ]] && (( ${#shortenedpath} > maxlength )) - do - current="${end%%/*}" # everything before the first / - end="${end#*/}" # everything after the first / - - shortcur="$current" - shortcurstar="$current" # No star if we don't shorten it. - - for ((i=${#current}-2; i>=0; i--)); do - subcurrent="${current:0:i}" - matching=("$begin/$subcurrent"*) # Array of all files that start with $subcurrent. - (( ${#matching[*]} != 1 )) && break # Stop shortening if more than one file matches. - shortcur="$subcurrent" - shortcurstar="$subcurrent*" - done - - #advance - begin="$begin/$current" - shortbegin="$shortbegin/$shortcurstar" - shortenedpath="$shortbegin/$end" - done - - shortenedpath="${shortenedpath%/}" # strip trailing / - shortenedpath="${shortenedpath#/}" # strip leading / - - # Replaces slashes with  except first occurence. - if [ $INHOME -eq 1 ]; then - echo "~/$shortenedpath" | sed "s/\///2g" # make sure it starts with ~/ - else - echo "/$shortenedpath" | sed "s/\///2g" # Make sure it starts with / - fi - - shopt "$NGV" nullglob # Reset nullglob in case this is being used as a function. +_swd() { + # Adapted from http://stackoverflow.com/a/2951707/1766716 + begin="" # The unshortened beginning of the path. + shortbegin="" # The shortened beginning of the path. + current="" # The section of the path we're currently working on. + end="${2:-${PWD}}/" # The unmodified rest of the path. + + if [[ "$end" =~ "$HOME" ]]; then + INHOME=1 + end="${end#$HOME}" #strip /home/username from start of string + begin="$HOME" #start expansion from the right spot + else + INHOME=0 + fi + + end="${end#/}" # Strip the first / + shortenedpath="$end" # The whole path, to check the length. + maxlength="${1:-0}" + + shopt -q nullglob && NGV="-s" || NGV="-u" # Store the value for later. + shopt -s nullglob # Without this, anything that doesn't exist in the filesystem turns into */*/*/... + + while [[ "$end" ]] && ((${#shortenedpath} > maxlength)); do + current="${end%%/*}" # everything before the first / + end="${end#*/}" # everything after the first / + + shortcur="$current" + shortcurstar="$current" # No star if we don't shorten it. + + for ((i = ${#current} - 2; i >= 0; i--)); do + subcurrent="${current:0:i}" + matching=("$begin/$subcurrent"*) # Array of all files that start with $subcurrent. + ((${#matching[*]} != 1)) && break # Stop shortening if more than one file matches. + shortcur="$subcurrent" + shortcurstar="$subcurrent*" + done + + #advance + begin="$begin/$current" + shortbegin="$shortbegin/$shortcurstar" + shortenedpath="$shortbegin/$end" + done + + shortenedpath="${shortenedpath%/}" # strip trailing / + shortenedpath="${shortenedpath#/}" # strip leading / + + # Replaces slashes with  except first occurence. + if [ $INHOME -eq 1 ]; then + echo "~/$shortenedpath" | sed "s/\///2g" # make sure it starts with ~/ + else + echo "/$shortenedpath" | sed "s/\///2g" # Make sure it starts with / + fi + + shopt "$NGV" nullglob # Reset nullglob in case this is being used as a function. } function set_rgb_color { - if [[ "${1}" != "-" ]]; then - fg="38;5;${1}" - fi - if [[ "${2}" != "-" ]]; then - bg="48;5;${2}" - [[ -n "${fg}" ]] && bg=";${bg}" - fi - echo -e "\[\033[${fg}${bg}m\]" + if [[ "${1}" != "-" ]]; then + fg="38;5;${1}" + fi + if [[ "${2}" != "-" ]]; then + bg="48;5;${2}" + [[ -n "${fg}" ]] && bg=";${bg}" + fi + echo -e "\[\033[${fg}${bg}m\]" } function powerline_shell_prompt { - if [[ -n "${SSH_CLIENT}" ]]; then - SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_SSH_THEME_PROMPT_COLOR}) ${SHELL_SSH_CHAR}\u@\h ${normal}" - LAST_THEME_COLOR=${SHELL_SSH_THEME_PROMPT_COLOR} - else - SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) ${normal}" - LAST_THEME_COLOR=${SHELL_THEME_PROMPT_COLOR} - fi + if [[ -n "${SSH_CLIENT}" ]]; then + SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_SSH_THEME_PROMPT_COLOR}) ${SHELL_SSH_CHAR}\u@\h ${normal}" + LAST_THEME_COLOR=${SHELL_SSH_THEME_PROMPT_COLOR} + else + SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) ${normal}" + LAST_THEME_COLOR=${SHELL_THEME_PROMPT_COLOR} + fi } function powerline_virtualenv_prompt { - local environ="" - - if [[ -n "$CONDA_DEFAULT_ENV" ]]; then - environ="conda: $CONDA_DEFAULT_ENV" - elif [[ -n "$VIRTUAL_ENV" ]]; then - environ=$(basename "$VIRTUAL_ENV") - fi - - if [[ -n "$environ" ]]; then - VIRTUALENV_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${VIRTUALENV_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}$environ ${normal}" - LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR} - else - VIRTUALENV_PROMPT="" - fi + local environ="" + + if [[ -n "$CONDA_DEFAULT_ENV" ]]; then + environ="conda: $CONDA_DEFAULT_ENV" + elif [[ -n "$VIRTUAL_ENV" ]]; then + environ=$(basename "$VIRTUAL_ENV") + fi + + if [[ -n "$environ" ]]; then + VIRTUALENV_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${VIRTUALENV_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}$environ ${normal}" + LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR} + else + VIRTUALENV_PROMPT="" + fi } function powerline_scm_prompt { - scm_prompt_vars - - if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then - if [[ "${SCM_DIRTY}" -eq 3 ]]; then - SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_STAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" - elif [[ "${SCM_DIRTY}" -eq 2 ]]; then - SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_UNSTAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" - elif [[ "${SCM_DIRTY}" -eq 1 ]]; then - SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})" - else - SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})" - fi - if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then - SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" - fi - SCM_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} ${normal}" - LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR} - else - SCM_PROMPT="" - fi + scm_prompt_vars + + if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then + if [[ "${SCM_DIRTY}" -eq 3 ]]; then + SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_STAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" + elif [[ "${SCM_DIRTY}" -eq 2 ]]; then + SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_UNSTAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" + elif [[ "${SCM_DIRTY}" -eq 1 ]]; then + SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})" + else + SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})" + fi + if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then + SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" + fi + SCM_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} ${normal}" + LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR} + else + SCM_PROMPT="" + fi } function powerline_cwd_prompt { -CWD_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${CWD_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}$(set_rgb_color 0 ${CWD_THEME_PROMPT_COLOR}) $(_swd)${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}" - LAST_THEME_COLOR=${CWD_THEME_PROMPT_COLOR} + CWD_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${CWD_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}$(set_rgb_color 0 ${CWD_THEME_PROMPT_COLOR}) $(_swd)${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}" + LAST_THEME_COLOR=${CWD_THEME_PROMPT_COLOR} } function powerline_last_status_prompt { - if [[ "$1" -eq 0 ]]; then - LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" - else - LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${LAST_STATUS_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${LAST_STATUS_THEME_PROMPT_COLOR}) ${LAST_STATUS} ${normal}$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" - fi + if [[ "$1" -eq 0 ]]; then + LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" + else + LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${LAST_STATUS_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${LAST_STATUS_THEME_PROMPT_COLOR}) ${LAST_STATUS} ${normal}$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" + fi } function powerline_prompt_command() { - local LAST_STATUS="$?" + local LAST_STATUS="$?" - powerline_shell_prompt - powerline_virtualenv_prompt - powerline_scm_prompt - powerline_cwd_prompt - powerline_last_status_prompt LAST_STATUS + powerline_shell_prompt + powerline_virtualenv_prompt + powerline_scm_prompt + powerline_cwd_prompt + powerline_last_status_prompt LAST_STATUS - PS1="${SHELL_PROMPT}${VIRTUALENV_PROMPT}${SCM_PROMPT}${CWD_PROMPT}${LAST_STATUS_PROMPT} " + PS1="${SHELL_PROMPT}${VIRTUALENV_PROMPT}${SCM_PROMPT}${CWD_PROMPT}${LAST_STATUS_PROMPT} " } PROMPT_COMMAND=powerline_prompt_command diff --git a/themes/primer/primer.theme.bash b/themes/primer/primer.theme.bash index c9cdb35d15..f6169cd039 100644 --- a/themes/primer/primer.theme.bash +++ b/themes/primer/primer.theme.bash @@ -2,7 +2,7 @@ # based of the candy theme, but minimized by odbol function prompt_command() { - PS1="$(clock_prompt) ${reset_color}${white}\w${reset_color}$(scm_prompt_info)${blue} →${bold_blue} ${reset_color} "; + PS1="$(clock_prompt) ${reset_color}${white}\w${reset_color}$(scm_prompt_info)${blue} →${bold_blue} ${reset_color} " } THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$blue"} diff --git a/themes/pro/pro.theme.bash b/themes/pro/pro.theme.bash index 1c7de29a34..449915bb34 100644 --- a/themes/pro/pro.theme.bash +++ b/themes/pro/pro.theme.bash @@ -11,12 +11,12 @@ GIT_THEME_PROMPT_PREFIX="${green}git:( " GIT_THEME_PROMPT_SUFFIX="${green} )" function git_prompt_info { - git_prompt_vars - echo -e "$SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_SUFFIX" + git_prompt_vars + echo -e "$SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_SUFFIX" } function prompt() { - PS1="\h: \W $(scm_prompt_info)${reset_color} $ " + PS1="\h: \W $(scm_prompt_info)${reset_color} $ " } safe_append_prompt_command prompt diff --git a/themes/radek/radek.theme.bash b/themes/radek/radek.theme.bash index bc47b01105..7983121174 100644 --- a/themes/radek/radek.theme.bash +++ b/themes/radek/radek.theme.bash @@ -13,7 +13,7 @@ PYTHON_THEME_PROMPT_PREFIX="${bold_green}[" PYTHON_THEME_PROMPT_SUFFIX="${bold_green}]" function prompt_command() { - PS1="\n${bold_white}[\u@\h]${bold_yellow}[\w] ${bold_cyan}$(scm_prompt_char_info)$(python_version_prompt)${green}\n→${reset_color} " + PS1="\n${bold_white}[\u@\h]${bold_yellow}[\w] ${bold_cyan}$(scm_prompt_char_info)$(python_version_prompt)${green}\n→${reset_color} " } safe_append_prompt_command prompt_command diff --git a/themes/rainbowbrite/rainbowbrite.theme.bash b/themes/rainbowbrite/rainbowbrite.theme.bash index 07e5843fcf..37cab72412 100644 --- a/themes/rainbowbrite/rainbowbrite.theme.bash +++ b/themes/rainbowbrite/rainbowbrite.theme.bash @@ -6,14 +6,14 @@ # in glorious red / blue / yellow color scheme prompt_setter() { - # Save history - _save-and-reload-history 1 - # displays user@server in purple - # PS1="$red$(scm_char) $purple\u@\h$reset_color:$blue\w$yellow$(scm_prompt_info)$(ruby_version_prompt) $black\$$reset_color " - # no user@server - PS1="$red$(scm_char) $blue\w$yellow$(scm_prompt_info)$(ruby_version_prompt) $black\$$reset_color " - PS2='> ' - PS4='+ ' + # Save history + _save-and-reload-history 1 + # displays user@server in purple + # PS1="$red$(scm_char) $purple\u@\h$reset_color:$blue\w$yellow$(scm_prompt_info)$(ruby_version_prompt) $black\$$reset_color " + # no user@server + PS1="$red$(scm_char) $blue\w$yellow$(scm_prompt_info)$(ruby_version_prompt) $black\$$reset_color " + PS2='> ' + PS4='+ ' } safe_append_prompt_command prompt_setter diff --git a/themes/ramses/ramses.theme.bash b/themes/ramses/ramses.theme.bash index 054a316024..ee4fdbdab1 100644 --- a/themes/ramses/ramses.theme.bash +++ b/themes/ramses/ramses.theme.bash @@ -11,79 +11,76 @@ SCM_HG_CHAR="${bold_red}☿${normal}" export MYSQL_PS1="(\u@\h) [\d]> " case $TERM in - xterm*) - TITLEBAR="\[\033]0;\w\007\]" - ;; - *) - TITLEBAR="" - ;; + xterm*) + TITLEBAR="\[\033]0;\w\007\]" + ;; + *) + TITLEBAR="" + ;; esac PS3=">> " __my_rvm_ruby_version() { - local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') - [ "$gemset" != "" ] && gemset="@$gemset" - local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') - local full="$version$gemset" - [ "$full" != "" ] && echo "[$full]" + local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') + [ "$gemset" != "" ] && gemset="@$gemset" + local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') + local full="$version$gemset" + [ "$full" != "" ] && echo "[$full]" } is_vim_shell() { - if [ ! -z "$VIMRUNTIME" ] - then - echo "[${cyan}vim shell${normal}]" - fi + if [ ! -z "$VIMRUNTIME" ]; then + echo "[${cyan}vim shell${normal}]" + fi } # show chroot if exist -chroot(){ - if [ -n "$debian_chroot" ] - then - my_ps_chroot="${bold_cyan}$debian_chroot${normal}"; - echo "($my_ps_chroot)"; - fi - } +chroot() { + if [ -n "$debian_chroot" ]; then + my_ps_chroot="${bold_cyan}$debian_chroot${normal}" + echo "($my_ps_chroot)" + fi +} # show virtualenvwrapper -my_ve(){ - - if [ -n "$CONDA_DEFAULT_ENV" ] - then - my_ps_ve="${bold_purple}${CONDA_DEFAULT_ENV}${normal}"; - echo "($my_ps_ve)"; - elif [ -n "$VIRTUAL_ENV" ] - then - my_ps_ve="${bold_purple}$ve${normal}"; - echo "($my_ps_ve)"; - fi - echo ""; - } +my_ve() { + + if [ -n "$CONDA_DEFAULT_ENV" ]; then + my_ps_ve="${bold_purple}${CONDA_DEFAULT_ENV}${normal}" + echo "($my_ps_ve)" + elif [ -n "$VIRTUAL_ENV" ]; then + my_ps_ve="${bold_purple}$ve${normal}" + echo "($my_ps_ve)" + fi + echo "" +} prompt() { - SCM_PROMPT_FORMAT='[%s][%s]' - my_ps_host="${green}\h${normal}"; - # yes, these are the the same for now ... - my_ps_host_root="${green}\h${normal}"; - - my_ps_user="${bold_green}\u${normal}" - my_ps_root="${bold_red}\u${normal}"; - - if [ -n "$VIRTUAL_ENV" ] - then - ve=`basename "$VIRTUAL_ENV"`; - fi - - # nice prompt - case "`id -u`" in - 0) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}] + SCM_PROMPT_FORMAT='[%s][%s]' + my_ps_host="${green}\h${normal}" + # yes, these are the the same for now ... + my_ps_host_root="${green}\h${normal}" + + my_ps_user="${bold_green}\u${normal}" + my_ps_root="${bold_red}\u${normal}" + + if [ -n "$VIRTUAL_ENV" ]; then + ve=$(basename "$VIRTUAL_ENV") + fi + + # nice prompt + case "$(id -u)" in + 0) + PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}] ▪ " - ;; - *) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version) + ;; + *) + PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version) |─[${bold_purple}\w${normal}] ▪ " - ;; - esac + ;; + esac } PS2="▪ " diff --git a/themes/rana/rana.theme.bash b/themes/rana/rana.theme.bash index 3da74d6db7..163c600936 100644 --- a/themes/rana/rana.theme.bash +++ b/themes/rana/rana.theme.bash @@ -32,37 +32,37 @@ #*color7: #E5E5E5 # ----------------------------------------------------------------- DEF COLOR -RCol='\e[0m' # Text Reset +RCol='\e[0m' # Text Reset # Regular -Bla='\e[0;30m'; -Red='\e[0;31m'; -Gre='\e[0;32m'; -Yel='\e[0;33m'; -Blu='\e[0;34m'; -Pur='\e[0;35m'; -Cya='\e[0;36m'; -Whi='\e[0;37m'; +Bla='\e[0;30m' +Red='\e[0;31m' +Gre='\e[0;32m' +Yel='\e[0;33m' +Blu='\e[0;34m' +Pur='\e[0;35m' +Cya='\e[0;36m' +Whi='\e[0;37m' # Bold -BBla='\e[1;30m'; -BRed='\e[1;31m'; -BYel='\e[1;33m'; -BGre='\e[1;32m'; -BBlu='\e[1;34m'; -BPur='\e[1;35m'; -BCya='\e[1;36m'; -BWhi='\e[1;37m'; +BBla='\e[1;30m' +BRed='\e[1;31m' +BYel='\e[1;33m' +BGre='\e[1;32m' +BBlu='\e[1;34m' +BPur='\e[1;35m' +BCya='\e[1;36m' +BWhi='\e[1;37m' # High Intensity -IBla='\e[0;90m'; -IRed='\e[0;91m'; -IGre='\e[0;92m'; -IYel='\e[0;93m'; -IBlu='\e[0;94m'; -IPur='\e[0;95m'; -ICya='\e[0;96m'; -IWhi='\e[0;97m'; +IBla='\e[0;90m' +IRed='\e[0;91m' +IGre='\e[0;92m' +IYel='\e[0;93m' +IBlu='\e[0;94m' +IPur='\e[0;95m' +ICya='\e[0;96m' +IWhi='\e[0;97m' # ----------------------------------------------------------------- COLOR CONF D_DEFAULT_COLOR="${Whi}" @@ -80,110 +80,108 @@ D_VIMSHELL_COLOR="${Cya}" # ------------------------------------------------------------------ FUNCTIONS case $TERM in - xterm*) - TITLEBAR="\033]0;\w\007" - ;; - *) - TITLEBAR="" - ;; + xterm*) + TITLEBAR="\033]0;\w\007" + ;; + *) + TITLEBAR="" + ;; esac is_vim_shell() { - if [ ! -z "$VIMRUNTIME" ]; - then - echo "${D_INTERMEDIATE_COLOR}on ${D_VIMSHELL_COLOR}\ + if [ ! -z "$VIMRUNTIME" ]; then + echo "${D_INTERMEDIATE_COLOR}on ${D_VIMSHELL_COLOR}\ vim shell${D_DEFAULT_COLOR} " - fi + fi } mitsuhikos_lastcommandfailed() { - code=$? - if [ $code != 0 ]; - then - echo "${D_INTERMEDIATE_COLOR}exited ${D_CMDFAIL_COLOR}\ + code=$? + if [ $code != 0 ]; then + echo "${D_INTERMEDIATE_COLOR}exited ${D_CMDFAIL_COLOR}\ $code ${D_DEFAULT_COLOR}" - fi + fi } # vcprompt for scm instead of bash_it default demula_vcprompt() { - if [ ! -z "$VCPROMPT_EXECUTABLE" ]; - then - local D_VCPROMPT_FORMAT="on ${D_SCM_COLOR}%s${D_INTERMEDIATE_COLOR}:\ + if [ ! -z "$VCPROMPT_EXECUTABLE" ]; then + local D_VCPROMPT_FORMAT="on ${D_SCM_COLOR}%s${D_INTERMEDIATE_COLOR}:\ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}" - $VCPROMPT_EXECUTABLE -f "$D_VCPROMPT_FORMAT" - fi + $VCPROMPT_EXECUTABLE -f "$D_VCPROMPT_FORMAT" + fi } # checks if the plugin is installed before calling battery_charge safe_battery_charge() { - if _command_exists battery_charge ; - then - battery_charge - fi + if _command_exists battery_charge; then + battery_charge + fi } prompt_git() { - local s=''; - local branchName=''; + local s='' + local branchName='' # Check if the current directory is in a Git repository. - if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then + if [ $( + git rev-parse --is-inside-work-tree &> /dev/null + echo "${?}" + ) == '0' ]; then # check if the current directory is in .git before running git checks if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]; then # Ensure the index is up to date. - git update-index --really-refresh -q &>/dev/null; + git update-index --really-refresh -q &> /dev/null # Check for uncommitted changes in the index. if ! $(git diff --quiet --ignore-submodules --cached); then - s+='+'; - fi; + s+='+' + fi # Check for unstaged changes. if ! $(git diff-files --quiet --ignore-submodules --); then - s+='!'; - fi; + s+='!' + fi # Check for untracked files. if [ -n "$(git ls-files --others --exclude-standard)" ]; then - s+='?'; - fi; + s+='?' + fi # Check for stashed files. - if $(git rev-parse --verify refs/stash &>/dev/null); then - s+='$'; - fi; + if $(git rev-parse --verify refs/stash &> /dev/null); then + s+='$' + fi - fi; + fi # Get the short symbolic ref. # If HEAD isn’t a symbolic ref, get the short SHA for the latest commit # Otherwise, just give up. - branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \ - git rev-parse --short HEAD 2> /dev/null || \ - echo '(unknown)')"; + branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null \ + || git rev-parse --short HEAD 2> /dev/null \ + || echo '(unknown)')" - [ -n "${s}" ] && s=" [${s}]"; + [ -n "${s}" ] && s=" [${s}]" - echo -e "${1}${branchName}${Cya}${s}"; + echo -e "${1}${branchName}${Cya}${s}" else - return; - fi; + return + fi } # -------------------------------------------------------------- PROMPT OUTPUT prompt() { - local LAST_COMMAND_FAILED=$(mitsuhikos_lastcommandfailed) - local SAVE_CURSOR='\033[s' - local RESTORE_CURSOR='\033[u' - local MOVE_CURSOR_RIGHTMOST='\033[500C' - local MOVE_CURSOR_5_LEFT='\033[5D' - - if [[ "$OSTYPE" == 'linux'* ]]; - then - PS1="${TITLEBAR} + local LAST_COMMAND_FAILED=$(mitsuhikos_lastcommandfailed) + local SAVE_CURSOR='\033[s' + local RESTORE_CURSOR='\033[u' + local MOVE_CURSOR_RIGHTMOST='\033[500C' + local MOVE_CURSOR_5_LEFT='\033[5D' + + if [[ "$OSTYPE" == 'linux'* ]]; then + PS1="${TITLEBAR} ${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}\ $(safe_battery_charge)${RESTORE_CURSOR}\ ${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\ @@ -194,8 +192,8 @@ ${LAST_COMMAND_FAILED}\ $(demula_vcprompt)\ $(is_vim_shell) ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" - else - PS1="${TITLEBAR} + else + PS1="${TITLEBAR} ${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\ at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\ in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\ @@ -205,9 +203,9 @@ $(demula_vcprompt)\ $(is_vim_shell)\ $(safe_battery_charge) ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" - fi + fi - PS2="${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" + PS2="${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" } # Runs prompt (this bypasses bash_it $PROMPT setting) diff --git a/themes/redline/redline.theme.bash b/themes/redline/redline.theme.bash index e8810106b4..65bf6f0a55 100644 --- a/themes/redline/redline.theme.bash +++ b/themes/redline/redline.theme.bash @@ -23,7 +23,7 @@ SCM_GIT_CHAR=${POWERLINE_SCM_GIT_CHAR:=" "} SCM_THEME_PROMPT_CLEAN="" SCM_THEME_PROMPT_DIRTY="" SCM_THEME_PROMPT_CLEAN_COLOR=235 -SCM_THEME_PROMPT_DIRTY_COLOR=235 #124 +SCM_THEME_PROMPT_DIRTY_COLOR=235 #124 SCM_THEME_PROMPT_STAGED_COLOR=235 #52 SCM_THEME_PROMPT_UNSTAGED_COLOR=88 SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} diff --git a/themes/rjorgenson/rjorgenson.theme.bash b/themes/rjorgenson/rjorgenson.theme.bash index 6e73c4a28c..c41ebff025 100644 --- a/themes/rjorgenson/rjorgenson.theme.bash +++ b/themes/rjorgenson/rjorgenson.theme.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2034,SC2154 # port of zork theme @@ -20,74 +21,74 @@ SCM_HG_CHAR="${bold_red}☿${normal}" export MYSQL_PS1="(\u@\h) [\d]> " case $TERM in - xterm*) - TITLEBAR="\[\033]0;\w\007\]" - ;; - *) - TITLEBAR="" - ;; + xterm*) + TITLEBAR="\[\033]0;\w\007\]" + ;; + *) + TITLEBAR="" + ;; esac PS3=">> " __my_rvm_ruby_version() { - local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') - [ "$gemset" != "" ] && gemset="@$gemset" - local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') - local full="$version$gemset" - [ "$full" != "" ] && echo "${BRACKET_COLOR}[${STRING_COLOR}$full${BRACKET_COLOR}]${normal}" + local gemset version full + gemset=$(echo "$GEM_HOME" | awk -F'@' '{print $2}') + [[ "$gemset" != "" ]] && gemset="@$gemset" + version=$(echo "$MY_RUBY_HOME" | awk -F'-' '{print $2}') + full="$version$gemset" + [[ "$full" != "" ]] && echo "${BRACKET_COLOR}[${STRING_COLOR}$full${BRACKET_COLOR}]${normal}" } is_vim_shell() { - if [ ! -z "$VIMRUNTIME" ] - then - echo "${BRACKET_COLOR}[${STRING_COLOR}vim shell${BRACKET_COLOR}]${normal}" - fi + if [[ -n "$VIMRUNTIME" ]]; then + echo "${BRACKET_COLOR}[${STRING_COLOR}vim shell${BRACKET_COLOR}]${normal}" + fi } function is_integer() { # helper function for todo-txt-count - [ "$1" -eq "$1" ] > /dev/null 2>&1 - return $? + [ "$1" -eq "$1" ] > /dev/null 2>&1 + return $? } todo_txt_count() { - if `hash todo.sh 2>&-`; then # is todo.sh installed - count=`todo.sh ls | grep -E "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 - fi + if hash todo.sh 2>&-; then # is todo.sh installed + count=$(todo.sh ls | grep -E "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 + fi } my_prompt_char() { - if [[ $OSTYPE =~ "darwin" ]]; then - echo "${BRACKET_COLOR}➞ ${normal}" - else - echo "${BRACKET_COLOR}➞ ${normal}" - fi + if [[ $OSTYPE =~ "darwin" ]]; then + echo "${BRACKET_COLOR}➞ ${normal}" + else + echo "${BRACKET_COLOR}➞ ${normal}" + fi } prompt() { SCM_PROMPT_FORMAT="${BRACKET_COLOR}[%s${BRACKET_COLOR}][${STRING_COLOR}%s${BRACKET_COLOR}]" - my_ps_host="${STRING_COLOR}\h${normal}"; - my_ps_user="${STRING_COLOR}\u${normal}"; - my_ps_root="${bold_red}\u${normal}"; - my_ps_path="${STRING_COLOR}\w${normal}"; + my_ps_host="${STRING_COLOR}\h${normal}" + my_ps_user="${STRING_COLOR}\u${normal}" + my_ps_root="${bold_red}\u${normal}" + my_ps_path="${STRING_COLOR}\w${normal}" - # nice prompt - case "`id -u`" in - 0) PS1="${TITLEBAR}${BRACKET_COLOR}┌─[$my_ps_root${BRACKET_COLOR}][$my_ps_host${BRACKET_COLOR}]$(scm_prompt)$(__my_rvm_ruby_version)${BRACKET_COLOR}[${STRING_COLOR}\w${BRACKET_COLOR}]$(is_vim_shell) + # nice prompt + case "$(id -u)" in + 0) + PS1="${TITLEBAR}${BRACKET_COLOR}┌─[$my_ps_root${BRACKET_COLOR}][$my_ps_host${BRACKET_COLOR}]$(scm_prompt)$(__my_rvm_ruby_version)${BRACKET_COLOR}[${STRING_COLOR}\w${BRACKET_COLOR}]$(is_vim_shell) ${BRACKET_COLOR}└─$(my_prompt_char)${normal}" - ;; - *) PS1="${TITLEBAR}${BRACKET_COLOR}┌─[$my_ps_user${BRACKET_COLOR}][$my_ps_host${BRACKET_COLOR}]$(scm_prompt)$(__my_rvm_ruby_version)${BRACKET_COLOR}[${STRING_COLOR}\w${BRACKET_COLOR}]$(is_vim_shell) + ;; + *) + PS1="${TITLEBAR}${BRACKET_COLOR}┌─[$my_ps_user${BRACKET_COLOR}][$my_ps_host${BRACKET_COLOR}]$(scm_prompt)$(__my_rvm_ruby_version)${BRACKET_COLOR}[${STRING_COLOR}\w${BRACKET_COLOR}]$(is_vim_shell) ${BRACKET_COLOR}└─$(todo_txt_count)$(my_prompt_char)" - ;; - esac + ;; + esac } PS2="└─$(my_prompt_char)" - - safe_append_prompt_command prompt diff --git a/themes/robbyrussell/robbyrussell.theme.bash b/themes/robbyrussell/robbyrussell.theme.bash index 956347dd5e..75ef54f8d2 100644 --- a/themes/robbyrussell/robbyrussell.theme.bash +++ b/themes/robbyrussell/robbyrussell.theme.bash @@ -14,12 +14,12 @@ RVM_THEME_PROMPT_PREFIX="|" RVM_THEME_PROMPT_SUFFIX="|" function git_prompt_info() { - git_prompt_vars - echo -e "$SCM_PREFIX${bold_red}$SCM_BRANCH$SCM_STATE$SCM_SUFFIX" + git_prompt_vars + echo -e "$SCM_PREFIX${bold_red}$SCM_BRANCH$SCM_STATE$SCM_SUFFIX" } function prompt_command() { - PS1="${bold_green}➜ ${bold_cyan}\W${reset_color}$(scm_prompt_info)${normal} " + PS1="${bold_green}➜ ${bold_cyan}\W${reset_color}$(scm_prompt_info)${normal} " } PROMPT_COMMAND=prompt_command diff --git a/themes/roderik/roderik.theme.bash b/themes/roderik/roderik.theme.bash index 8a1c1045e5..cb7252784e 100644 --- a/themes/roderik/roderik.theme.bash +++ b/themes/roderik/roderik.theme.bash @@ -7,11 +7,11 @@ export GIT_PS1_SHOWSTASHSTATE=true export PROMPT_DIRTRIM=3 function prompt_command() { - if [[ ${EUID} == 0 ]] ; then - PS1="[$(clock_prompt)]${yellow}[${red}\u@\h ${green}\w${yellow}]${red}$(__git_ps1 "(%s)")${normal}\\$ " - else - PS1="[$(clock_prompt)]${yellow}[${cyan}\u@\h ${green}\w${yellow}]${red}$(__git_ps1 "(%s)")${normal}\\$ " - fi + if [[ ${EUID} == 0 ]]; then + PS1="[$(clock_prompt)]${yellow}[${red}\u@\h ${green}\w${yellow}]${red}$(__git_ps1 "(%s)")${normal}\\$ " + else + PS1="[$(clock_prompt)]${yellow}[${cyan}\u@\h ${green}\w${yellow}]${red}$(__git_ps1 "(%s)")${normal}\\$ " + fi } safe_append_prompt_command prompt_command diff --git a/themes/sexy/sexy.theme.bash b/themes/sexy/sexy.theme.bash index 41d195d28b..6a59c66528 100644 --- a/themes/sexy/sexy.theme.bash +++ b/themes/sexy/sexy.theme.bash @@ -10,47 +10,47 @@ SEXY_THEME_SHOW_PYTHON="${SEXY_THEME_SHOW_PYTHON:=false}" if tput setaf 1 &> /dev/null; then - if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then - MAGENTA=$(tput setaf 9) - ORANGE=$(tput setaf 172) - GREEN=$(tput setaf 190) - PURPLE=$(tput setaf 141) - WHITE=$(tput setaf 0) - else - MAGENTA=$(tput setaf 5) - ORANGE=$(tput setaf 4) - GREEN=$(tput setaf 2) - PURPLE=$(tput setaf 1) - WHITE=$(tput setaf 7) - fi - BOLD=$(tput bold) - RESET=$(tput sgr0) + if [[ $(tput colors) -ge 256 ]] 2> /dev/null; then + MAGENTA=$(tput setaf 9) + ORANGE=$(tput setaf 172) + GREEN=$(tput setaf 190) + PURPLE=$(tput setaf 141) + WHITE=$(tput setaf 0) + else + MAGENTA=$(tput setaf 5) + ORANGE=$(tput setaf 4) + GREEN=$(tput setaf 2) + PURPLE=$(tput setaf 1) + WHITE=$(tput setaf 7) + fi + BOLD=$(tput bold) + RESET=$(tput sgr0) else - MAGENTA="\033[1;31m" - ORANGE="\033[1;33m" - GREEN="\033[1;32m" - PURPLE="\033[1;35m" - WHITE="\033[1;37m" - BOLD="" - RESET="\033[m" + MAGENTA="\033[1;31m" + ORANGE="\033[1;33m" + GREEN="\033[1;32m" + PURPLE="\033[1;35m" + WHITE="\033[1;37m" + BOLD="" + RESET="\033[m" fi -parse_git_dirty () { - [[ $(git status 2> /dev/null | tail -n1 | cut -c 1-17) != "nothing to commit" ]] && echo "*" +parse_git_dirty() { + [[ $(git status 2> /dev/null | tail -n1 | cut -c 1-17) != "nothing to commit" ]] && echo "*" } -parse_git_branch () { - git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" +parse_git_branch() { + git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" } -env_prompt () { - echo -e "($(virtualenv_prompt)$(condaenv_prompt))" +env_prompt() { + echo -e "($(virtualenv_prompt)$(condaenv_prompt))" } function prompt_command() { - PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]at \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\n\$ \[$RESET\]" + PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]at \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\n\$ \[$RESET\]" - if [ "$SEXY_THEME_SHOW_PYTHON" = true ] ; then - PS1="\[${BOLD}${WHITE}\]$(env_prompt) "$PS1 - fi + if [ "$SEXY_THEME_SHOW_PYTHON" = true ]; then + PS1="\[${BOLD}${WHITE}\]$(env_prompt) "$PS1 + fi } safe_append_prompt_command prompt_command diff --git a/themes/simple/simple.theme.bash b/themes/simple/simple.theme.bash index 6db7f4b44a..5f34636c58 100644 --- a/themes/simple/simple.theme.bash +++ b/themes/simple/simple.theme.bash @@ -5,11 +5,11 @@ #added TITLEBAR for updating the tab and window titles with the pwd case $TERM in xterm*) - TITLEBAR="\[\033]0;\w\007\]" - ;; + TITLEBAR="\[\033]0;\w\007\]" + ;; *) - TITLEBAR="" - ;; + TITLEBAR="" + ;; esac function prompt_command() { diff --git a/themes/sirup/sirup.theme.bash b/themes/sirup/sirup.theme.bash index 235de0180a..73e957837f 100644 --- a/themes/sirup/sirup.theme.bash +++ b/themes/sirup/sirup.theme.bash @@ -2,21 +2,21 @@ GIT_PS1_SHOWDIRTYSTATE="enabled" function rvm_version_prompt { - local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') + local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') - [ "$gemset" != "" ] && gemset="@$gemset" - local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') + [ "$gemset" != "" ] && gemset="@$gemset" + local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') - [ "$version" == "1.9.2" ] && version="" + [ "$version" == "1.9.2" ] && version="" - local full="$version$gemset" + local full="$version$gemset" - [ "$full" != "" ] && echo "$full" + [ "$full" != "" ] && echo "$full" } function prompt_command() { - # Check http://github.com/Sirupsen/dotfiles for screenshot - PS1="$blue\W/$bold_blue$(rvm_version_prompt)$bold_green$(__git_ps1 " (%s)") ${normal}$ " + # Check http://github.com/Sirupsen/dotfiles for screenshot + PS1="$blue\W/$bold_blue$(rvm_version_prompt)$bold_green$(__git_ps1 " (%s)") ${normal}$ " } safe_append_prompt_command prompt_command diff --git a/themes/slick/slick.theme.bash b/themes/slick/slick.theme.bash index b0979b7cb8..f4b59aa14a 100644 --- a/themes/slick/slick.theme.bash +++ b/themes/slick/slick.theme.bash @@ -11,66 +11,67 @@ SCM_HG_CHAR="${bold_red}☿${normal}" export MYSQL_PS1="(\u@\h) [\d]> " case $TERM in - xterm*) - TITLEBAR="\[\033]0;\w\007\]" - ;; - *) - TITLEBAR="" - ;; + xterm*) + TITLEBAR="\[\033]0;\w\007\]" + ;; + *) + TITLEBAR="" + ;; esac PS3=">> " __my_rvm_ruby_version() { - local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') - [ "$gemset" != "" ] && gemset="@$gemset" - local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') - local full="$version$gemset" - [ "$full" != "" ] && echo "[$full]" + local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') + [ "$gemset" != "" ] && gemset="@$gemset" + local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') + local full="$version$gemset" + [ "$full" != "" ] && echo "[$full]" } __my_venv_prompt() { - if [ ! -z "$VIRTUAL_ENV" ] - then - echo "[${blue}@${normal}${VIRTUAL_ENV##*/}]" - fi + if [ ! -z "$VIRTUAL_ENV" ]; then + echo "[${blue}@${normal}${VIRTUAL_ENV##*/}]" + fi } is_vim_shell() { - if [ ! -z "$VIMRUNTIME" ] - then - echo "[${cyan}vim shell${normal}]" - fi + if [ ! -z "$VIMRUNTIME" ]; then + echo "[${cyan}vim shell${normal}]" + fi } prompt() { - SCM_PROMPT_FORMAT='[%s][%s]' - case $HOSTNAME in - "clappy"* ) my_ps_host="${green}\h${normal}"; - ;; - "icekernel") my_ps_host="${red}\h${normal}"; - ;; - * ) my_ps_host="${green}\h${normal}"; - ;; - esac + SCM_PROMPT_FORMAT='[%s][%s]' + case $HOSTNAME in + "clappy"*) + my_ps_host="${green}\h${normal}" + ;; + "icekernel") + my_ps_host="${red}\h${normal}" + ;; + *) + my_ps_host="${green}\h${normal}" + ;; + esac - my_ps_user="\[\033[01;32m\]\u\[\033[00m\]"; - my_ps_root="\[\033[01;31m\]\u\[\033[00m\]"; - my_ps_path="\[\033[01;36m\]\w\[\033[00m\]"; + my_ps_user="\[\033[01;32m\]\u\[\033[00m\]" + my_ps_root="\[\033[01;31m\]\u\[\033[00m\]" + my_ps_path="\[\033[01;36m\]\w\[\033[00m\]" - # nice prompt - case "`id -u`" in - 0) PS1="${TITLEBAR}[$my_ps_root][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) + # nice prompt + case "$(id -u)" in + 0) + PS1="${TITLEBAR}[$my_ps_root][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) $ " - ;; - *) PS1="${TITLEBAR}[$my_ps_user][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version)$(__my_venv_prompt)[${cyan}\w${normal}]$(is_vim_shell) + ;; + *) + PS1="${TITLEBAR}[$my_ps_user][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version)$(__my_venv_prompt)[${cyan}\w${normal}]$(is_vim_shell) $ " - ;; - esac + ;; + esac } PS2="> " - - safe_append_prompt_command prompt diff --git a/themes/standard/standard.theme.bash b/themes/standard/standard.theme.bash index 561a97cbe1..1f9f8795d7 100644 --- a/themes/standard/standard.theme.bash +++ b/themes/standard/standard.theme.bash @@ -10,15 +10,15 @@ SCM_THEME_PROMPT_SUFFIX="" #added TITLEBAR for updating the tab and window titles with the pwd case $TERM in xterm*) - TITLEBAR='\[\033]0;\w\007\]' - ;; + TITLEBAR='\[\033]0;\w\007\]' + ;; *) - TITLEBAR="" - ;; + TITLEBAR="" + ;; esac function prompt_command() { - PROMPT='${green}\u${normal}@${green}\h${normal}:${blue}\w${normal}${red}$(prompt_char)$(git_prompt_info)${normal}\$ ' + PROMPT='${green}\u${normal}@${green}\h${normal}:${blue}\w${normal}${red}$(prompt_char)$(git_prompt_info)${normal}\$ ' } safe_append_prompt_command prompt_command diff --git a/themes/tonka/tonka.theme.bash b/themes/tonka/tonka.theme.bash index e97a5712a3..06f091f300 100644 --- a/themes/tonka/tonka.theme.bash +++ b/themes/tonka/tonka.theme.bash @@ -1,41 +1,40 @@ #!/usr/bin/env bash __tonka_time() { - THEME_CLOCK_FORMAT="%H%M" - clock_prompt + THEME_CLOCK_FORMAT="%H%M" + clock_prompt } __tonka_date() { - THEME_CLOCK_FORMAT="%a,%d %b %y" - clock_prompt + THEME_CLOCK_FORMAT="%a,%d %b %y" + clock_prompt } __tonka_clock() { - local LIGHT_BLUE="\[\033[1;34m\]" - if [[ "${THEME_SHOW_CLOCK}" = "true" ]]; then - echo "$(__tonka_time)${LIGHT_BLUE}:$(__tonka_date)${LIGHT_BLUE}:" - fi + local LIGHT_BLUE="\[\033[1;34m\]" + if [[ "${THEME_SHOW_CLOCK}" = "true" ]]; then + echo "$(__tonka_time)${LIGHT_BLUE}:$(__tonka_date)${LIGHT_BLUE}:" + fi } prompt_setter() { -# Named "Tonka" because of the colour scheme -local WHITE="\[\033[1;37m\]" -local LIGHT_BLUE="\[\033[1;34m\]" -local YELLOW="\[\033[1;33m\]" -local NO_COLOUR="\[\033[0m\]" - -case $TERM in - xterm*|rxvt*) - TITLEBAR='\[\033]0;\u@\h:\w\007\]' - ;; - *) - TITLEBAR="" - ;; -esac - -PS1="$TITLEBAR\ -$YELLOW-$LIGHT_BLUE-(\ + # Named "Tonka" because of the colour scheme + local WHITE="\[\033[1;37m\]" + local LIGHT_BLUE="\[\033[1;34m\]" + local YELLOW="\[\033[1;33m\]" + local NO_COLOUR="\[\033[0m\]" + + case $TERM in + xterm* | rxvt*) + TITLEBAR='\[\033]0;\u@\h:\w\007\]' + ;; + *) + TITLEBAR="" + ;; + esac + + PS1="$TITLEBAR$YELLOW-$LIGHT_BLUE-(\ $YELLOW\u$LIGHT_BLUE@$YELLOW\h\ $LIGHT_BLUE)-(\ $YELLOW\$PWD\ @@ -45,7 +44,7 @@ $YELLOW-$LIGHT_BLUE-(\ $(__tonka_clock)\ $WHITE\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR " -PS2="$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR " + PS2="$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR " } @@ -56,6 +55,6 @@ THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"\[\033[1;33m\]"} export PS3=">> " -LS_COLORS='no=00:fi=00:di=00;33:ln=01;36:pi=40;34:so=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.deb=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.mpg=01;37:*.avi=01;37:*.gl=01;37:*.dl=01;37:'; +LS_COLORS='no=00:fi=00:di=00;33:ln=01;36:pi=40;34:so=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.deb=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.mpg=01;37:*.avi=01;37:*.gl=01;37:*.dl=01;37:' export LS_COLORS diff --git a/themes/tonotdo/tonotdo.theme.bash b/themes/tonotdo/tonotdo.theme.bash index 347e586b05..63296eaad7 100644 --- a/themes/tonotdo/tonotdo.theme.bash +++ b/themes/tonotdo/tonotdo.theme.bash @@ -7,7 +7,7 @@ SCM_THEME_PROMPT_CLEAN=" ${green}✓" SCM_GIT_SHOW_DETAILS="false" function prompt_command() { - PS1="${yellow}\u${normal}${cyan}@\h${normal}${purple} ${normal}${green}\w${normal}$(scm_prompt_info)> " + PS1="${yellow}\u${normal}${cyan}@\h${normal}${purple} ${normal}${green}\w${normal}$(scm_prompt_info)> " } safe_append_prompt_command prompt_command diff --git a/themes/tylenol/tylenol.theme.bash b/themes/tylenol/tylenol.theme.bash index a48dceb416..560be51912 100644 --- a/themes/tylenol/tylenol.theme.bash +++ b/themes/tylenol/tylenol.theme.bash @@ -14,7 +14,7 @@ VIRTUALENV_THEME_PROMPT_PREFIX='|' VIRTUALENV_THEME_PROMPT_SUFFIX='|' function prompt_command() { - PS1="\n${green}$(virtualenv_prompt)${red}$(ruby_version_prompt) ${reset_color}\h ${orange}in ${reset_color}\w\n${yellow}$(scm_char)$(scm_prompt_info) ${yellow}→${white} " + PS1="\n${green}$(virtualenv_prompt)${red}$(ruby_version_prompt) ${reset_color}\h ${orange}in ${reset_color}\w\n${yellow}$(scm_char)$(scm_prompt_info) ${yellow}→${white} " } safe_append_prompt_command prompt_command diff --git a/themes/wanelo/wanelo.theme.bash b/themes/wanelo/wanelo.theme.bash index 437fd3272b..88d174014d 100644 --- a/themes/wanelo/wanelo.theme.bash +++ b/themes/wanelo/wanelo.theme.bash @@ -13,14 +13,14 @@ RVM_THEME_PROMPT_PREFIX="|" RVM_THEME_PROMPT_SUFFIX="|" function prompt_command() { - if [ $? -eq 0 ]; then - status=❤️ - else - status=💔 - fi - PS1="\n${yellow}$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w $status \n${bold_cyan} ${blue}|$(clock_prompt)|${green}$(scm_prompt_info) ${green}→${reset_color} " + if [ $? -eq 0 ]; then + status=❤️ + else + status=💔 + fi + PS1="\n${yellow}$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w $status \n${bold_cyan} ${blue}|$(clock_prompt)|${green}$(scm_prompt_info) ${green}→${reset_color} " } THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$blue"} -PROMPT_COMMAND=prompt_command; +PROMPT_COMMAND=prompt_command diff --git a/themes/zitron/zitron.theme.bash b/themes/zitron/zitron.theme.bash index 56b7bfa63a..7100052702 100644 --- a/themes/zitron/zitron.theme.bash +++ b/themes/zitron/zitron.theme.bash @@ -14,11 +14,11 @@ export LSCOLORS="Gxfxcxdxbxegedabagacad" export LS_COLORS="no=00:fi=00:di=01;33:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.svgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;34:*.svg=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:" function prompt_command() { - ## look-a-like - # user:host:pwd git-branch(*)$ - # for example: - # noqqe:deathstar:themes master*$ - PS1="${no_color}\u:$(hostname)${normal}:${bold_yellow}\W/${normal} $(git_prompt_info)${reset_color}$ " + ## look-a-like + # user:host:pwd git-branch(*)$ + # for example: + # noqqe:deathstar:themes master*$ + PS1="${no_color}\u:$(hostname)${normal}:${bold_yellow}\W/${normal} $(git_prompt_info)${reset_color}$ " } safe_append_prompt_command prompt_command diff --git a/themes/zork/zork.theme.bash b/themes/zork/zork.theme.bash index c80534501a..034b92054a 100644 --- a/themes/zork/zork.theme.bash +++ b/themes/zork/zork.theme.bash @@ -11,82 +11,77 @@ SCM_HG_CHAR="${bold_red}☿${normal}" export MYSQL_PS1="(\u@\h) [\d]> " case $TERM in - xterm*) - TITLEBAR="\[\033]0;\w\007\]" - ;; - *) - TITLEBAR="" - ;; + xterm*) + TITLEBAR="\[\033]0;\w\007\]" + ;; + *) + TITLEBAR="" + ;; esac PS3=">> " __my_rvm_ruby_version() { - local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') - [ "$gemset" != "" ] && gemset="@$gemset" - local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') - local full="$version$gemset" - [ "$full" != "" ] && echo "[$full]" + local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') + [ "$gemset" != "" ] && gemset="@$gemset" + local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') + local full="$version$gemset" + [ "$full" != "" ] && echo "[$full]" } is_vim_shell() { - if [ ! -z "$VIMRUNTIME" ] - then - echo "[${cyan}vim shell${normal}]" - fi + if [ ! -z "$VIMRUNTIME" ]; then + echo "[${cyan}vim shell${normal}]" + fi } # show chroot if exist -chroot(){ - if [ -n "$debian_chroot" ] - then - my_ps_chroot="${bold_cyan}$debian_chroot${normal}"; - echo "($my_ps_chroot)"; - fi - } +chroot() { + if [ -n "$debian_chroot" ]; then + my_ps_chroot="${bold_cyan}$debian_chroot${normal}" + echo "($my_ps_chroot)" + fi +} # show virtualenvwrapper -my_ve(){ - - if [ -n "$CONDA_DEFAULT_ENV" ] - then - my_ps_ve="${bold_purple}${CONDA_DEFAULT_ENV}${normal}"; - echo "($my_ps_ve)"; - elif [ -n "$VIRTUAL_ENV" ] - then - my_ps_ve="${bold_purple}$ve${normal}"; - echo "($my_ps_ve)"; - fi - echo ""; - } +my_ve() { + + if [ -n "$CONDA_DEFAULT_ENV" ]; then + my_ps_ve="${bold_purple}${CONDA_DEFAULT_ENV}${normal}" + echo "($my_ps_ve)" + elif [ -n "$VIRTUAL_ENV" ]; then + my_ps_ve="${bold_purple}$ve${normal}" + echo "($my_ps_ve)" + fi + echo "" +} prompt() { SCM_PROMPT_FORMAT='[%s][%s]' - my_ps_host="${green}\h${normal}"; - # yes, these are the the same for now ... - my_ps_host_root="${green}\h${normal}"; + my_ps_host="${green}\h${normal}" + # yes, these are the the same for now ... + my_ps_host_root="${green}\h${normal}" - my_ps_user="${bold_green}\u${normal}" - my_ps_root="${bold_red}\u${normal}"; + my_ps_user="${bold_green}\u${normal}" + my_ps_root="${bold_red}\u${normal}" - if [ -n "$VIRTUAL_ENV" ] - then - ve=`basename "$VIRTUAL_ENV"`; - fi + if [ -n "$VIRTUAL_ENV" ]; then + ve=$(basename "$VIRTUAL_ENV") + fi - # nice prompt - case "`id -u`" in - 0) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) + # nice prompt + case "$(id -u)" in + 0) + PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) └─▪ " - ;; - *) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) + ;; + *) + PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) └─▪ " - ;; - esac + ;; + esac } PS2="└─▪ " - - safe_append_prompt_command prompt diff --git a/uninstall.sh b/uninstall.sh index f1e559bdcf..49a816da8c 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,16 +1,15 @@ #!/usr/bin/env bash -if [ -z "$BASH_IT" ]; -then - BASH_IT="$HOME/.bash_it" +if [ -z "$BASH_IT" ]; then + BASH_IT="$HOME/.bash_it" fi case $OSTYPE in - darwin*) - CONFIG_FILE=.bash_profile - ;; - *) - CONFIG_FILE=.bashrc - ;; + darwin*) + CONFIG_FILE=.bash_profile + ;; + *) + CONFIG_FILE=.bashrc + ;; esac # overriding CONFIG_FILE: @@ -19,16 +18,16 @@ CONFIG_FILE="${BASH_IT_CONFIG_FILE:-"${CONFIG_FILE}"}" BACKUP_FILE=$CONFIG_FILE.bak if [ ! -e "$HOME/$BACKUP_FILE" ]; then - echo -e "\033[0;33mBackup file $HOME/$BACKUP_FILE not found.\033[0m" >&2 + echo -e "\033[0;33mBackup file $HOME/$BACKUP_FILE not found.\033[0m" >&2 - test -w "$HOME/$CONFIG_FILE" && - mv "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.uninstall" && - echo -e "\033[0;32mMoved your $HOME/$CONFIG_FILE to $HOME/$CONFIG_FILE.uninstall.\033[0m" + test -w "$HOME/$CONFIG_FILE" \ + && mv "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.uninstall" \ + && echo -e "\033[0;32mMoved your $HOME/$CONFIG_FILE to $HOME/$CONFIG_FILE.uninstall.\033[0m" else - test -w "$HOME/$BACKUP_FILE" && - cp -a "$HOME/$BACKUP_FILE" "$HOME/$CONFIG_FILE" && - rm "$HOME/$BACKUP_FILE" && - echo -e "\033[0;32mYour original $CONFIG_FILE has been restored.\033[0m" + test -w "$HOME/$BACKUP_FILE" \ + && cp -a "$HOME/$BACKUP_FILE" "$HOME/$CONFIG_FILE" \ + && rm "$HOME/$BACKUP_FILE" \ + && echo -e "\033[0;32mYour original $CONFIG_FILE has been restored.\033[0m" fi echo "" diff --git a/vendor/github.com/dsifford/yarn-completion/yarn b/vendor/github.com/dsifford/yarn-completion/yarn index ff78e47137..5eb68a7aa9 100644 --- a/vendor/github.com/dsifford/yarn-completion/yarn +++ b/vendor/github.com/dsifford/yarn-completion/yarn @@ -1205,4 +1205,4 @@ if [[ ${BASH_VERSINFO[0]} -ge 4 && ${BASH_VERSINFO[1]} -ge 4 ]]; then complete -o nosort -F _yarn yarn else complete -F _yarn yarn -fi \ No newline at end of file +fi diff --git a/vendor/github.com/erichs/composure/c_extras.sh b/vendor/github.com/erichs/composure/c_extras.sh index d975e20db5..2970d42db0 100644 --- a/vendor/github.com/erichs/composure/c_extras.sh +++ b/vendor/github.com/erichs/composure/c_extras.sh @@ -1,25 +1,25 @@ #!/bin/bash -_basename_no_extension () { - sed -e 's/^.*\/\(.*\)\.inc$/\1/' +_basename_no_extension() { + sed -e 's/^.*\/\(.*\)\.inc$/\1/' } -_composure_functions () { - _list_composure_files | _basename_no_extension +_composure_functions() { + _list_composure_files | _basename_no_extension } -_load_tab_completions () { - # support tab completion for 'revise' command - # you may disable this by adding the following line to your shell startup: - # export COMPOSURE_TAB_COMPLETION=0 +_load_tab_completions() { + # support tab completion for 'revise' command + # you may disable this by adding the following line to your shell startup: + # export COMPOSURE_TAB_COMPLETION=0 - if [ "$COMPOSURE_TAB_COMPLETION" = "0" ]; then - return # if you say so... - fi + if [ "$COMPOSURE_TAB_COMPLETION" = "0" ]; then + return # if you say so... + fi - case "$(_shell)" in - zsh) - read -r -d '' SCRIPT <> $grouplist.$group; - echo $grouplist.$group >> $grouplist; - done; - # clear progress message - printf '\r%s\n' ' ' - typeset group; - typeset gfile; - for gfile in $(cat $grouplist | sort | uniq); - do - printf '%s\n' "${gfile##*.}:"; - cat $gfile; - printf '\n'; - command rm $gfile 2> /dev/null; - done | less - command rm $grouplist 2> /dev/null +overview() { + about 'gives overview of available shell functions, by group' + group 'composure' + + # display a brief progress message... + printf '%s' 'building documentation...' + typeset grouplist=$(mktemp /tmp/grouplist.XXXX) + typeset func + for func in $(_typeset_functions); do + typeset group="$(typeset -f $func | metafor group)" + if [ -z "$group" ]; then + group='misc' + fi + typeset about="$(typeset -f $func | metafor about)" + _letterpress "$about" $func >> $grouplist.$group + echo $grouplist.$group >> $grouplist + done + # clear progress message + printf '\r%s\n' ' ' + typeset group + typeset gfile + for gfile in $(cat $grouplist | sort | uniq); do + printf '%s\n' "${gfile##*.}:" + cat $gfile + printf '\n' + command rm $gfile 2> /dev/null + done | less + command rm $grouplist 2> /dev/null } -recompose () -{ - about 'loads a stored function from ~/.composure repo' - param '1: name of function' - example '$ load myfunc' - group 'composure' +recompose() { + about 'loads a stored function from ~/.composure repo' + param '1: name of function' + example '$ load myfunc' + group 'composure' - . $(_get_composure_dir)/$1.inc + . $(_get_composure_dir)/$1.inc } -unique_metafor () -{ - about 'displays all unique metadata for a given keyword' - param '1: keyword' - example '$ unique_metafor group' - group 'composure' +unique_metafor() { + about 'displays all unique metadata for a given keyword' + param '1: keyword' + example '$ unique_metafor group' + group 'composure' - typeset keyword=$1 + typeset keyword=$1 - typeset file=$(mktemp /tmp/composure.XXXX) - typeset -f | metafor $keyword >> $file - cat $file | sort | uniq - command rm $file 2>/dev/null + typeset file=$(mktemp /tmp/composure.XXXX) + typeset -f | metafor $keyword >> $file + cat $file | sort | uniq + command rm $file 2> /dev/null } -compost () { +compost() { about 'delete function stored in composure repo' param '1: name of function' example '$ compost myfunc' group 'composure' - typeset func=$1 - [ -z "$func" ] && echo "you must specify a function name!" && return 1 + typeset func=$1 + [ -z "$func" ] && echo "you must specify a function name!" && return 1 - ( - cd $(_get_composure_dir) - git rm "$func.inc" && git commit -m "Delete function $func" - ) + ( + cd $(_get_composure_dir) + git rm "$func.inc" && git commit -m "Delete function $func" + ) } _load_tab_completions diff --git a/vendor/github.com/erichs/composure/composure.sh b/vendor/github.com/erichs/composure/composure.sh index ae11f9b36c..a5efad4e23 100755 --- a/vendor/github.com/erichs/composure/composure.sh +++ b/vendor/github.com/erichs/composure/composure.sh @@ -12,60 +12,55 @@ # 'plumbing' functions _bootstrap_composure() { - _generate_metadata_functions - _load_composed_functions - _determine_printf_cmd + _generate_metadata_functions + _load_composed_functions + _determine_printf_cmd } -_get_composure_dir () -{ - if [ -n "${XDG_DATA_HOME:-}" ]; then - echo "$XDG_DATA_HOME/composure" - else - echo "$HOME/.local/composure" - fi +_get_composure_dir() { + if [ -n "${XDG_DATA_HOME:-}" ]; then + echo "$XDG_DATA_HOME/composure" + else + echo "$HOME/.local/composure" + fi } -_get_author_name () -{ - typeset name localname - localname="$(git --git-dir "$(_get_composure_dir)/.git" config --get user.name)" - for name in "${GIT_AUTHOR_NAME:-}" "$localname"; do - if [ -n "$name" ]; then - echo "$name" - break - fi - done +_get_author_name() { + typeset name localname + localname="$(git --git-dir "$(_get_composure_dir)/.git" config --get user.name)" + for name in "${GIT_AUTHOR_NAME:-}" "$localname"; do + if [ -n "$name" ]; then + echo "$name" + break + fi + done } -_composure_keywords () -{ - echo "about author example group param version" +_composure_keywords() { + echo "about author example group param version" } -_letterpress () -{ - typeset rightcol="$1" leftcol="${2:- }" leftwidth="${3:-20}" +_letterpress() { + typeset rightcol="$1" leftcol="${2:- }" leftwidth="${3:-20}" - if [ -z "$rightcol" ]; then - return - fi + if [ -z "$rightcol" ]; then + return + fi - $_printf_cmd "%-*s%s\n" "$leftwidth" "$leftcol" "$rightcol" + $_printf_cmd "%-*s%s\n" "$leftwidth" "$leftcol" "$rightcol" } _determine_printf_cmd() { - if [ -z "${_printf_cmd:-}" ]; then - _printf_cmd=printf - # prefer GNU gprintf if available - [ -x "$(which gprintf 2>/dev/null)" ] && _printf_cmd=gprintf - export _printf_cmd - fi + if [ -z "${_printf_cmd:-}" ]; then + _printf_cmd=printf + # prefer GNU gprintf if available + [ -x "$(which gprintf 2> /dev/null)" ] && _printf_cmd=gprintf + export _printf_cmd + fi } -_longest_function_name_length () -{ - echo "$1" | awk 'BEGIN{ maxlength=0 } +_longest_function_name_length() { + echo "$1" | awk 'BEGIN{ maxlength=0 } { for(i=1;i<=NF;i++) if (length($i)>maxlength) @@ -76,246 +71,239 @@ _longest_function_name_length () END{ print maxlength}' } -_temp_filename_for () -{ - typeset file="$(mktemp "/tmp/$1.XXXX")" - command rm "$file" 2>/dev/null # ensure file is unlinked prior to use - echo "$file" +_temp_filename_for() { + typeset file="$(mktemp "/tmp/$1.XXXX")" + command rm "$file" 2> /dev/null # ensure file is unlinked prior to use + echo "$file" } -_prompt () -{ - typeset prompt="$1" - typeset result - case "$(_shell)" in - bash) - read -r -e -p "$prompt" result;; - *) - echo -n "$prompt" >&2; read -r result;; - esac - echo "$result" +_prompt() { + typeset prompt="$1" + typeset result + case "$(_shell)" in + bash) + read -r -e -p "$prompt" result + ;; + *) + echo -n "$prompt" >&2 + read -r result + ;; + esac + echo "$result" } -_add_composure_file () -{ - typeset func="$1" - typeset file="$2" - typeset operation="$3" - typeset comment="${4:-}" - typeset composure_dir=$(_get_composure_dir) - - ( - if ! cd "$composure_dir"; then - printf "%s\n" "Oops! Can't find $composure_dir!" - return - fi - if git rev-parse 2>/dev/null; then - if [ ! -f "$file" ]; then - printf "%s\n" "Oops! Couldn't find $file to version it for you..." - return - fi - cp "$file" "$composure_dir/$func.inc" - git add --all . - if [ -z "$comment" ]; then - comment="$(_prompt 'Git Comment: ')" - fi - git commit -m "$operation $func: $comment" - fi - ) +_add_composure_file() { + typeset func="$1" + typeset file="$2" + typeset operation="$3" + typeset comment="${4:-}" + typeset composure_dir=$(_get_composure_dir) + + ( + if ! cd "$composure_dir"; then + printf "%s\n" "Oops! Can't find $composure_dir!" + return + fi + if git rev-parse 2> /dev/null; then + if [ ! -f "$file" ]; then + printf "%s\n" "Oops! Couldn't find $file to version it for you..." + return + fi + cp "$file" "$composure_dir/$func.inc" + git add --all . + if [ -z "$comment" ]; then + comment="$(_prompt 'Git Comment: ')" + fi + git commit -m "$operation $func: $comment" + fi + ) } -_transcribe () -{ - typeset func="$1" - typeset file="$2" - typeset operation="$3" - typeset comment="${4:-}" - typeset composure_dir=$(_get_composure_dir) - - if git --version >/dev/null 2>&1; then - if [ -d "$composure_dir" ]; then - _add_composure_file "$func" "$file" "$operation" "$comment" - else - if [ "${USE_COMPOSURE_REPO:-}" = "0" ]; then - return # if you say so... - fi - printf "%s\n" "I see you don't have a $composure_dir repo..." - typeset input='' - typeset valid=0 - while [ $valid != 1 ]; do - printf "\n%s" 'would you like to create one? y/n: ' - read -r input - case $input in - y|yes|Y|Yes|YES) - ( - echo 'creating git repository for your functions...' - mkdir -p "$composure_dir" || return 1 - cd "$composure_dir" || return 1 - git init - echo "composure stores your function definitions here" > README.txt - git add README.txt - git commit -m 'initial commit' - ) - # if at first you don't succeed... - _transcribe "$func" "$file" "$operation" "$comment" - valid=1 - ;; - n|no|N|No|NO) - printf "%s\n" "ok. add 'export USE_COMPOSURE_REPO=0' to your startup script to disable this message." - valid=1 - ;; - *) - printf "%s\n" "sorry, didn't get that..." - ;; - esac - done - fi - fi +_transcribe() { + typeset func="$1" + typeset file="$2" + typeset operation="$3" + typeset comment="${4:-}" + typeset composure_dir=$(_get_composure_dir) + + if git --version > /dev/null 2>&1; then + if [ -d "$composure_dir" ]; then + _add_composure_file "$func" "$file" "$operation" "$comment" + else + if [ "${USE_COMPOSURE_REPO:-}" = "0" ]; then + return # if you say so... + fi + printf "%s\n" "I see you don't have a $composure_dir repo..." + typeset input='' + typeset valid=0 + while [ $valid != 1 ]; do + printf "\n%s" 'would you like to create one? y/n: ' + read -r input + case $input in + y | yes | Y | Yes | YES) + ( + echo 'creating git repository for your functions...' + mkdir -p "$composure_dir" || return 1 + cd "$composure_dir" || return 1 + git init + echo "composure stores your function definitions here" > README.txt + git add README.txt + git commit -m 'initial commit' + ) + # if at first you don't succeed... + _transcribe "$func" "$file" "$operation" "$comment" + valid=1 + ;; + n | no | N | No | NO) + printf "%s\n" "ok. add 'export USE_COMPOSURE_REPO=0' to your startup script to disable this message." + valid=1 + ;; + *) + printf "%s\n" "sorry, didn't get that..." + ;; + esac + done + fi + fi } -_typeset_functions () -{ - # unfortunately, there does not seem to be a easy, portable way to list just the - # names of the defined shell functions... - - case "$(_shell)" in - sh|bash) - typeset -F | awk '{print $3}' - ;; - *) - # trim everything following '()' in ksh/zsh - typeset +f | sed 's/().*$//' - ;; - esac +_typeset_functions() { + # unfortunately, there does not seem to be a easy, portable way to list just the + # names of the defined shell functions... + + case "$(_shell)" in + sh | bash) + typeset -F | awk '{print $3}' + ;; + *) + # trim everything following '()' in ksh/zsh + typeset +f | sed 's/().*$//' + ;; + esac } -_typeset_functions_about () -{ - typeset f - for f in $(_typeset_functions); do - typeset -f -- "$f" | grep -qE "^about[[:space:]]|[[:space:]]about[[:space:]]" && echo -- "$f" - done +_typeset_functions_about() { + typeset f + for f in $(_typeset_functions); do + typeset -f -- "$f" | grep -qE "^about[[:space:]]|[[:space:]]about[[:space:]]" && echo -- "$f" + done } -_shell () { - # here's a hack I modified from a StackOverflow post: - # get the ps listing for the current process ($$), and print the last column (CMD) - # stripping any leading hyphens shells sometimes throw in there - typeset this=$(ps -o comm -p $$ | tail -1 | awk '{print $NF}' | sed 's/^-*//') - echo "${this##*/}" # e.g. /bin/bash => bash +_shell() { + # here's a hack I modified from a StackOverflow post: + # get the ps listing for the current process ($$), and print the last column (CMD) + # stripping any leading hyphens shells sometimes throw in there + typeset this=$(ps -o comm -p $$ | tail -1 | awk '{print $NF}' | sed 's/^-*//') + echo "${this##*/}" # e.g. /bin/bash => bash } _generate_metadata_functions() { - typeset f - for f in $(_composure_keywords) - do - eval "$f() { :; }" - done + typeset f + for f in $(_composure_keywords); do + eval "$f() { :; }" + done } -_list_composure_files () { - typeset composure_dir="$(_get_composure_dir)" - [ -d "$composure_dir" ] && find "$composure_dir" -maxdepth 1 -name '*.inc' +_list_composure_files() { + typeset composure_dir="$(_get_composure_dir)" + [ -d "$composure_dir" ] && find "$composure_dir" -maxdepth 1 -name '*.inc' } -_load_composed_functions () { - # load previously composed functions into shell - # you may disable this by adding the following line to your shell startup: - # export LOAD_COMPOSED_FUNCTIONS=0 +_load_composed_functions() { + # load previously composed functions into shell + # you may disable this by adding the following line to your shell startup: + # export LOAD_COMPOSED_FUNCTIONS=0 - if [ "${LOAD_COMPOSED_FUNCTIONS:-}" = "0" ]; then - return # if you say so... - fi + if [ "${LOAD_COMPOSED_FUNCTIONS:-}" = "0" ]; then + return # if you say so... + fi - typeset inc - for inc in $(_list_composure_files); do - # shellcheck source=/dev/null - . "$inc" - done + typeset inc + for inc in $(_list_composure_files); do + # shellcheck source=/dev/null + . "$inc" + done } -_strip_trailing_whitespace () { - sed -e 's/ \+$//' +_strip_trailing_whitespace() { + sed -e 's/ \+$//' } -_strip_semicolons () { - sed -e 's/;$//' +_strip_semicolons() { + sed -e 's/;$//' } - # 'porcelain' functions -cite () -{ - about 'creates one or more meta keywords for use in your functions' - param 'one or more keywords' - example '$ cite url username' - example '$ url http://somewhere.com' - example '$ username alice' - group 'composure' - - # this is the storage half of the 'metadata' system: - # we create dynamic metadata keywords with function wrappers around - # the NOP command, ':' - - # anything following a keyword will get parsed as a positional - # parameter, but stay resident in the ENV. As opposed to shell - # comments, '#', which do not get parsed and are not available - # at runtime. - - # a BIG caveat--your metadata must be roughly parsable: do not use - # contractions, and consider single or double quoting if it contains - # non-alphanumeric characters - - if [ -z "$1" ]; then - printf '%s\n' 'missing parameter(s)' - reference cite - return - fi - - typeset keyword - for keyword in "$@"; do - eval "$keyword() { :; }" - done +cite() { + about 'creates one or more meta keywords for use in your functions' + param 'one or more keywords' + example '$ cite url username' + example '$ url http://somewhere.com' + example '$ username alice' + group 'composure' + + # this is the storage half of the 'metadata' system: + # we create dynamic metadata keywords with function wrappers around + # the NOP command, ':' + + # anything following a keyword will get parsed as a positional + # parameter, but stay resident in the ENV. As opposed to shell + # comments, '#', which do not get parsed and are not available + # at runtime. + + # a BIG caveat--your metadata must be roughly parsable: do not use + # contractions, and consider single or double quoting if it contains + # non-alphanumeric characters + + if [ -z "$1" ]; then + printf '%s\n' 'missing parameter(s)' + reference cite + return + fi + + typeset keyword + for keyword in "$@"; do + eval "$keyword() { :; }" + done } -draft () -{ - about 'wraps command from history into a new function, default is last command' - param '1: name to give function' - param '2: optional history line number' - example '$ ls' - example '$ draft list' - example '$ draft newfunc 1120 # wraps command at history line 1120 in newfunc()' - group 'composure' - - typeset func=$1 - typeset num=$2 - - if [ -z "$func" ]; then - printf '%s\n' 'missing parameter(s)' - reference draft - return - fi - - # aliases bind tighter than function names, disallow them - if type -a "$func" 2>/dev/null | grep -q 'is.*alias'; then - printf '%s\n' "sorry, $(type -a "$func"). please choose another name." - return - fi - - typeset cmd - if [ -z "$num" ]; then - # some versions of 'fix command, fc' need corrective lenses... - typeset lines=$(fc -ln -1 | grep -q draft && echo 2 || echo 1) - # parse last command from fc output - # shellcheck disable=SC2086 - cmd=$(fc -ln -$lines | head -1 | sed 's/^[[:blank:]]*//') - else - # parse command from history line number - cmd=$(eval "history | grep '^[[:blank:]]*$num' | head -1" | sed 's/^[[:blank:][:digit:]]*//') - fi - eval "function $func { +draft() { + about 'wraps command from history into a new function, default is last command' + param '1: name to give function' + param '2: optional history line number' + example '$ ls' + example '$ draft list' + example '$ draft newfunc 1120 # wraps command at history line 1120 in newfunc()' + group 'composure' + + typeset func=$1 + typeset num=$2 + + if [ -z "$func" ]; then + printf '%s\n' 'missing parameter(s)' + reference draft + return + fi + + # aliases bind tighter than function names, disallow them + if type -a "$func" 2> /dev/null | grep -q 'is.*alias'; then + printf '%s\n' "sorry, $(type -a "$func"). please choose another name." + return + fi + + typeset cmd + if [ -z "$num" ]; then + # some versions of 'fix command, fc' need corrective lenses... + typeset lines=$(fc -ln -1 | grep -q draft && echo 2 || echo 1) + # parse last command from fc output + # shellcheck disable=SC2086 + cmd=$(fc -ln -$lines | head -1 | sed 's/^[[:blank:]]*//') + else + # parse command from history line number + cmd=$(eval "history | grep '^[[:blank:]]*$num' | head -1" | sed 's/^[[:blank:][:digit:]]*//') + fi + eval "function $func { author '$(_get_author_name)' about '' param '' @@ -324,196 +312,190 @@ draft () $cmd; }" - typeset file=$(_temp_filename_for draft) - typeset -f "$func" | _strip_trailing_whitespace | _strip_semicolons > "$file" - _transcribe "$func" "$file" Draft "Initial draft" - command rm "$file" 2>/dev/null - revise "$func" + typeset file=$(_temp_filename_for draft) + typeset -f "$func" | _strip_trailing_whitespace | _strip_semicolons > "$file" + _transcribe "$func" "$file" Draft "Initial draft" + command rm "$file" 2> /dev/null + revise "$func" } -glossary () -{ - about 'displays help summary for all functions, or summary for a group of functions' - param '1: optional, group name' - example '$ glossary' - example '$ glossary misc' - group 'composure' - - typeset targetgroup=${1:-} - typeset functionlist="$(_typeset_functions_about)" - typeset maxwidth=$(_longest_function_name_length "$functionlist" | awk '{print $1 + 5}') - - for func in $(echo $functionlist); do - - if [ "X${targetgroup}X" != "XX" ]; then - typeset group="$(typeset -f -- $func | metafor group)" - if [ "$group" != "$targetgroup" ]; then - continue # skip non-matching groups, if specified - fi - fi - typeset about="$(typeset -f -- $func | metafor about)" - typeset aboutline= - echo "$about" | fmt | while read -r aboutline; do - _letterpress "$aboutline" "$func" "$maxwidth" - func=" " # only display function name once - done - done +glossary() { + about 'displays help summary for all functions, or summary for a group of functions' + param '1: optional, group name' + example '$ glossary' + example '$ glossary misc' + group 'composure' + + typeset targetgroup=${1:-} + typeset functionlist="$(_typeset_functions_about)" + typeset maxwidth=$(_longest_function_name_length "$functionlist" | awk '{print $1 + 5}') + + for func in $(echo $functionlist); do + + if [ "X${targetgroup}X" != "XX" ]; then + typeset group="$(typeset -f -- $func | metafor group)" + if [ "$group" != "$targetgroup" ]; then + continue # skip non-matching groups, if specified + fi + fi + typeset about="$(typeset -f -- $func | metafor about)" + typeset aboutline= + echo "$about" | fmt | while read -r aboutline; do + _letterpress "$aboutline" "$func" "$maxwidth" + func=" " # only display function name once + done + done } -metafor () -{ - about 'prints function metadata associated with keyword' - param '1: meta keyword' - example '$ typeset -f glossary | metafor example' - group 'composure' +metafor() { + about 'prints function metadata associated with keyword' + param '1: meta keyword' + example '$ typeset -f glossary | metafor example' + group 'composure' - typeset keyword=$1 + typeset keyword=$1 - if [ -z "$keyword" ]; then - printf '%s\n' 'missing parameter(s)' - reference metafor - return - fi + if [ -z "$keyword" ]; then + printf '%s\n' 'missing parameter(s)' + reference metafor + return + fi - # this sed-fu is the retrieval half of the 'metadata' system: - # 'grep' for the metadata keyword, and then parse/filter the matching line + # this sed-fu is the retrieval half of the 'metadata' system: + # 'grep' for the metadata keyword, and then parse/filter the matching line - # grep keyword # strip trailing '|"|; # ignore thru keyword and leading '|" - sed -n "/$keyword / s/['\";]*\$//;s/^[ ]*\(: _\)*$keyword ['\"]*\([^([].*\)*\$/\2/p" + # grep keyword # strip trailing '|"|; # ignore thru keyword and leading '|" + sed -n "/$keyword / s/['\";]*\$//;s/^[ ]*\(: _\)*$keyword ['\"]*\([^([].*\)*\$/\2/p" } -reference () -{ - about 'displays apidoc help for a specific function' - param '1: function name' - example '$ reference revise' - group 'composure' - - typeset func=$1 - if [ -z "$func" ]; then - printf '%s\n' 'missing parameter(s)' - reference reference - return - fi - - typeset line - - typeset about="$(typeset -f "$func" | metafor about)" - _letterpress "$about" "$func" - - typeset author="$(typeset -f $func | metafor author)" - if [ -n "$author" ]; then - _letterpress "$author" 'author:' - fi - - typeset version="$(typeset -f $func | metafor version)" - if [ -n "$version" ]; then - _letterpress "$version" 'version:' - fi - - if [ -n "$(typeset -f $func | metafor param)" ]; then - printf "parameters:\n" - typeset -f $func | metafor param | while read -r line - do - _letterpress "$line" - done - fi - - if [ -n "$(typeset -f $func | metafor example)" ]; then - printf "examples:\n" - typeset -f $func | metafor example | while read -r line - do - _letterpress "$line" - done - fi +reference() { + about 'displays apidoc help for a specific function' + param '1: function name' + example '$ reference revise' + group 'composure' + + typeset func=$1 + if [ -z "$func" ]; then + printf '%s\n' 'missing parameter(s)' + reference reference + return + fi + + typeset line + + typeset about="$(typeset -f "$func" | metafor about)" + _letterpress "$about" "$func" + + typeset author="$(typeset -f $func | metafor author)" + if [ -n "$author" ]; then + _letterpress "$author" 'author:' + fi + + typeset version="$(typeset -f $func | metafor version)" + if [ -n "$version" ]; then + _letterpress "$version" 'version:' + fi + + if [ -n "$(typeset -f $func | metafor param)" ]; then + printf "parameters:\n" + typeset -f $func | metafor param | while read -r line; do + _letterpress "$line" + done + fi + + if [ -n "$(typeset -f $func | metafor example)" ]; then + printf "examples:\n" + typeset -f $func | metafor example | while read -r line; do + _letterpress "$line" + done + fi } -revise () -{ - about 'loads function into editor for revision' - param ' -e: revise version stored in ENV' - param '1: name of function' - example '$ revise myfunction' - example '$ revise -e myfunction' - example 'save a zero-length file to abort revision' - group 'composure' - - typeset source='git' - if [ "$1" = '-e' ]; then - source='env' - shift - fi - - typeset func=$1 - if [ -z "$func" ]; then - printf '%s\n' 'missing parameter(s)' - reference revise - return - fi - - typeset composure_dir=$(_get_composure_dir) - typeset temp=$(_temp_filename_for revise) - # populate tempfile... - if [ "$source" = 'env' ] || [ ! -f "$composure_dir/$func.inc" ]; then - # ...with ENV if specified or not previously versioned - typeset -f $func > $temp - else - # ...or with contents of latest git revision - cat "$composure_dir/$func.inc" > "$temp" - fi - - if [ -z "${EDITOR:-}" ] - then - typeset EDITOR=vi - fi - - $EDITOR "$temp" - if [ -s "$temp" ]; then - typeset edit='N' - - # source edited file - # shellcheck source=/dev/null - . "$temp" || edit='Y' - - while [ $edit = 'Y' ]; do - echo -n "Re-edit? Y/N: " - read -r edit - case $edit in - y|yes|Y|Yes|YES) - edit='Y' - $EDITOR "$temp" - # shellcheck source=/dev/null - . "$temp" && edit='N';; - *) - edit='N';; - esac - done - _transcribe "$func" "$temp" Revise - else - # zero-length files abort revision - printf '%s\n' 'zero-length file, revision aborted!' - fi - command rm "$temp" +revise() { + about 'loads function into editor for revision' + param ' -e: revise version stored in ENV' + param '1: name of function' + example '$ revise myfunction' + example '$ revise -e myfunction' + example 'save a zero-length file to abort revision' + group 'composure' + + typeset source='git' + if [ "$1" = '-e' ]; then + source='env' + shift + fi + + typeset func=$1 + if [ -z "$func" ]; then + printf '%s\n' 'missing parameter(s)' + reference revise + return + fi + + typeset composure_dir=$(_get_composure_dir) + typeset temp=$(_temp_filename_for revise) + # populate tempfile... + if [ "$source" = 'env' ] || [ ! -f "$composure_dir/$func.inc" ]; then + # ...with ENV if specified or not previously versioned + typeset -f $func > $temp + else + # ...or with contents of latest git revision + cat "$composure_dir/$func.inc" > "$temp" + fi + + if [ -z "${EDITOR:-}" ]; then + typeset EDITOR=vi + fi + + $EDITOR "$temp" + if [ -s "$temp" ]; then + typeset edit='N' + + # source edited file + # shellcheck source=/dev/null + . "$temp" || edit='Y' + + while [ $edit = 'Y' ]; do + echo -n "Re-edit? Y/N: " + read -r edit + case $edit in + y | yes | Y | Yes | YES) + edit='Y' + $EDITOR "$temp" + # shellcheck source=/dev/null + . "$temp" && edit='N' + ;; + *) + edit='N' + ;; + esac + done + _transcribe "$func" "$temp" Revise + else + # zero-length files abort revision + printf '%s\n' 'zero-length file, revision aborted!' + fi + command rm "$temp" } -write () -{ -about 'writes one or more composed function definitions to stdout' -param 'one or more function names' -example '$ write finddown foo' -example '$ write finddown' -group 'composure' +write() { + about 'writes one or more composed function definitions to stdout' + param 'one or more function names' + example '$ write finddown foo' + example '$ write finddown' + group 'composure' -if [ -z "$1" ]; then - printf '%s\n' 'missing parameter(s)' - reference write - return -fi + if [ -z "$1" ]; then + printf '%s\n' 'missing parameter(s)' + reference write + return + fi -echo "#!/usr/bin/env ${SHELL##*/}" + echo "#!/usr/bin/env ${SHELL##*/}" -# bootstrap metadata -cat < $datafile + www.shellcheck.net/shellcheck.php > $datafile cat $datafile | python -mjson.tool > $metricfile rm $datafile cat $metricfile @@ -14,17 +14,17 @@ cat $metricfile # check for shellcheck.net errors cat $metricfile | grep -q error if [ $? -eq 0 ]; then - echo "! shellcheck.net:../composure.sh:0 [ errors ] FAILED" - rm $metricfile - exit 2 + echo "! shellcheck.net:../composure.sh:0 [ errors ] FAILED" + rm $metricfile + exit 2 fi # check for shellcheck.net warnings cat $metricfile | grep -q warning if [ $? -eq 0 ]; then - echo "! shellcheck.net:../composure.sh:0 [ warnings ] FAILED" - rm $metricfile - exit 2 + echo "! shellcheck.net:../composure.sh:0 [ warnings ] FAILED" + rm $metricfile + exit 2 fi echo "! shellcheck.net:../composure.sh:0 [ no errors or warnings ] ok" diff --git a/vendor/github.com/gaelicWizard/bash-progcomp/defaults.completion.bash b/vendor/github.com/gaelicWizard/bash-progcomp/defaults.completion.bash index 67cb4fe5cb..088d22715f 100644 --- a/vendor/github.com/gaelicWizard/bash-progcomp/defaults.completion.bash +++ b/vendor/github.com/gaelicWizard/bash-progcomp/defaults.completion.bash @@ -16,9 +16,9 @@ function matchpattern() function _defaults_verbs() { - local IFS=$'\n' # Treat only newlines as delimiters in string operations. - local LC_CTYPE='C' # Do not consider character set in string operations. - local LC_COLLATE='C' # Do not consider character set in pattern matching. + local IFS=$'\n' # Treat only newlines as delimiters in string operations. + local LC_CTYPE='C' # Do not consider character set in string operations. + local LC_COLLATE='C' # Do not consider character set in pattern matching. local cur="${COMP_WORDS[COMP_CWORD]}" local prev="${COMP_WORDS[COMP_CWORD - 1]}" COMPREPLY=() @@ -41,15 +41,14 @@ function _defaults_verbs() function _defaults_domains() { - local IFS=$'\n' # Treat only newlines as delimiters in string operations. - local LC_CTYPE='C' # Do not consider character set in string operations. - local LC_COLLATE='C' # Do not consider character set in pattern matching. + local IFS=$'\n' # Treat only newlines as delimiters in string operations. + local LC_CTYPE='C' # Do not consider character set in string operations. + local LC_COLLATE='C' # Do not consider character set in pattern matching. local cur="${COMP_WORDS[COMP_CWORD]}" local prev="${COMP_WORDS[COMP_CWORD - 1]}" COMPREPLY=() - if [[ "$BASH_VERSINFO" -ge 4 ]] - then # Exponential performance issue on strings greater than about 10k. + if [[ "$BASH_VERSINFO" -ge 4 ]]; then # Exponential performance issue on strings greater than about 10k. local domains="$(defaults domains)" local candidates=($(compgen -W "${domains//, /$IFS}" | grep -i "^${cur}")) else @@ -57,11 +56,9 @@ function _defaults_domains() local candidates=($(compgen -W "${domains}" | grep -i "^${cur}")) fi COMPREPLY=($(printf '%q\n' "${candidates[@]}")) - if grep -q "^$cur" <<< '-app' - then + if grep -q "^$cur" <<< '-app'; then COMPREPLY[${#COMPREPLY[@]}]="-app" - elif grep -q "^$cur" <<< '-g' - then + elif grep -q "^$cur" <<< '-g'; then COMPREPLY[${#COMPREPLY[@]}]="-g" fi @@ -70,9 +67,9 @@ function _defaults_domains() function _defaults() { - local IFS=$'\n' # Treat only newlines as delimiters in string operations. - local LC_CTYPE='C' # Do not consider character set in string operations. - local LC_COLLATE='C' # Do not consider character set in pattern matching. + local IFS=$'\n' # Treat only newlines as delimiters in string operations. + local LC_CTYPE='C' # Do not consider character set in string operations. + local LC_COLLATE='C' # Do not consider character set in pattern matching. local cur="${COMP_WORDS[COMP_CWORD]}" local prev="${COMP_WORDS[COMP_CWORD - 1]}" COMPREPLY=() @@ -97,8 +94,7 @@ function _defaults() _known_hosts -a ;; *) - if matchpattern "$prev" "${cmds// /|}" - then + if matchpattern "$prev" "${cmds// /|}"; then # TODO: not correct for verbs: domains, find, help _defaults_domains else @@ -123,8 +119,7 @@ function _defaults() 4) case ${COMP_WORDS[1]} in "-host") - if matchpattern "$prev" "${cmds// /|}" - then + if matchpattern "$prev" "${cmds// /|}"; then # TODO: not correct for verbs: domains, find, help _defaults_domains else @@ -139,15 +134,12 @@ function _defaults() case ${COMP_WORDS[1]} in "-currentHost") - if matchpattern "${COMP_WORDS[2]}" "${cmds// /|}" - then + if matchpattern "${COMP_WORDS[2]}" "${cmds// /|}"; then cmd="${COMP_WORDS[2]}" domain="${COMP_WORDS[3]}" key_index=4 - if [[ "$domain" == "-app" ]] - then - if [[ $COMP_CWORD -eq 4 ]] - then + if [[ "$domain" == "-app" ]]; then + if [[ $COMP_CWORD -eq 4 ]]; then # Completing application name. Can't help here, sorry return 0 fi @@ -157,15 +149,12 @@ function _defaults() fi ;; "-host") - if matchpattern "${COMP_WORDS[3]}" "${cmds// /|}" - then + if matchpattern "${COMP_WORDS[3]}" "${cmds// /|}"; then cmd="${COMP_WORDS[3]}" domain="${COMP_WORDS[4]}" key_index=5 - if [[ "$domain" == "-app" ]] - then - if [[ $COMP_CWORD -eq 5 ]] - then + if [[ "$domain" == "-app" ]]; then + if [[ $COMP_CWORD -eq 5 ]]; then # Completing application name. Can't help here, sorry return 0 fi @@ -175,15 +164,12 @@ function _defaults() fi ;; *) - if matchpattern "${COMP_WORDS[1]}" "${cmds// /|}" - then + if matchpattern "${COMP_WORDS[1]}" "${cmds// /|}"; then cmd="${COMP_WORDS[1]}" domain="${COMP_WORDS[2]}" key_index=3 - if [[ "$domain" == "-app" ]] - then - if [[ $COMP_CWORD -eq 3 ]] - then + if [[ "$domain" == "-app" ]]; then + if [[ $COMP_CWORD -eq 3 ]]; then # Completing application name. Can't help here, sorry return 0 fi @@ -200,51 +186,41 @@ function _defaults() case $cmd in read | read-type) # Complete key - if candidates=($(compgen -W "${keys[*]:-}" | grep -i "^${cur}")) - then + if candidates=($(compgen -W "${keys[*]:-}" | grep -i "^${cur}")); then COMPREPLY=($(printf '%q\n' "${candidates[@]}")) fi ;; write) - if [[ $key_index -eq $COMP_CWORD ]] - then + if [[ $key_index -eq $COMP_CWORD ]]; then # Complete key - if candidates=($(compgen -W "${keys[*]:-}" | grep -i "^${cur}")) - then + if candidates=($(compgen -W "${keys[*]:-}" | grep -i "^${cur}")); then COMPREPLY=($(printf '%q\n' "${candidates[@]}")) fi - elif [[ $((key_index + 1)) -eq $COMP_CWORD ]] - then + elif [[ $((key_index + 1)) -eq $COMP_CWORD ]]; then # Complete value type local cur_type="$(defaults read-type "$domain" "${COMP_WORDS[key_index]}" 2> /dev/null | sed -e 's/^Type is \(.*\)/-\1/' -e's/dictionary/dict/' | grep "^$cur")" - if [[ $cur_type ]] - then + if [[ $cur_type ]]; then COMPREPLY=("$cur_type") else COMPREPLY=($(compgen -W "${value_types[*]}" -- "$cur")) fi - elif [[ $((key_index + 2)) -eq $COMP_CWORD ]] - then + elif [[ $((key_index + 2)) -eq $COMP_CWORD ]]; then # Complete value COMPREPLY=($(defaults read "$domain" "${COMP_WORDS[key_index]}" 2> /dev/null | grep -i "^${cur//\\/\\\\}")) fi ;; rename) - if [[ $key_index -eq $COMP_CWORD || $((key_index + 1)) -eq $COMP_CWORD ]] - then + if [[ $key_index -eq $COMP_CWORD || $((key_index + 1)) -eq $COMP_CWORD ]]; then # Complete source and destination keys - if candidates=($(compgen -W "${keys[*]:-}" | grep -i "^${cur}")) - then + if candidates=($(compgen -W "${keys[*]:-}" | grep -i "^${cur}")); then COMPREPLY=($(printf '%q\n' "${candidates[@]}")) fi fi ;; delete) - if [[ $key_index -eq $COMP_CWORD ]] - then + if [[ $key_index -eq $COMP_CWORD ]]; then # Complete key - if candidates=($(compgen -W "${keys[*]:-}" | grep -i "^${cur}")) - then + if candidates=($(compgen -W "${keys[*]:-}" | grep -i "^${cur}")); then COMPREPLY=($(printf '%q\n' "${candidates[@]}")) fi fi diff --git a/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh b/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh index 5f1208c33e..b78aacbd80 100644 --- a/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh +++ b/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh @@ -34,12 +34,12 @@ # Make sure this is bash that's running and return otherwise. if [[ -z "${BASH_VERSION:-}" ]]; then - return 1; + return 1 fi # Avoid duplicate inclusion if [[ -n "${bash_preexec_imported:-}" ]]; then - return 0 + return 0 fi bash_preexec_imported="defined" @@ -65,27 +65,27 @@ __bp_install_string=$'__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_in # Fails if any of the given variables are readonly # Reference https://stackoverflow.com/a/4441178 __bp_require_not_readonly() { - local var - for var; do - if ! ( unset "$var" 2> /dev/null ); then - echo "bash-preexec requires write access to ${var}" >&2 - return 1 - fi - done + local var + for var; do + if ! (unset "$var" 2> /dev/null); then + echo "bash-preexec requires write access to ${var}" >&2 + return 1 + fi + done } # Remove ignorespace and or replace ignoreboth from HISTCONTROL # so we can accurately invoke preexec with a command from our # history even if it starts with a space. __bp_adjust_histcontrol() { - local histcontrol - histcontrol="${HISTCONTROL:-}" - histcontrol="${histcontrol//ignorespace}" - # Replace ignoreboth with ignoredups - if [[ "$histcontrol" == *"ignoreboth"* ]]; then - histcontrol="ignoredups:${histcontrol//ignoreboth}" - fi; - export HISTCONTROL="$histcontrol" + local histcontrol + histcontrol="${HISTCONTROL:-}" + histcontrol="${histcontrol//ignorespace/}" + # Replace ignoreboth with ignoredups + if [[ "$histcontrol" == *"ignoreboth"* ]]; then + histcontrol="ignoredups:${histcontrol//ignoreboth/}" + fi + export HISTCONTROL="$histcontrol" } # This variable describes whether we are currently in "interactive mode"; @@ -102,86 +102,84 @@ declare -a preexec_functions # Trims leading and trailing whitespace from $2 and writes it to the variable # name passed as $1 __bp_trim_whitespace() { - local var=${1:?} text=${2:-} - text="${text#"${text%%[![:space:]]*}"}" # remove leading whitespace characters - text="${text%"${text##*[![:space:]]}"}" # remove trailing whitespace characters - printf -v "$var" '%s' "$text" + local var=${1:?} text=${2:-} + text="${text#"${text%%[![:space:]]*}"}" # remove leading whitespace characters + text="${text%"${text##*[![:space:]]}"}" # remove trailing whitespace characters + printf -v "$var" '%s' "$text" } - # Trims whitespace and removes any leading or trailing semicolons from $2 and # writes the resulting string to the variable name passed as $1. Used for # manipulating substrings in PROMPT_COMMAND __bp_sanitize_string() { - local var=${1:?} text=${2:-} sanitized - __bp_trim_whitespace sanitized "$text" - sanitized=${sanitized%;} - sanitized=${sanitized#;} - __bp_trim_whitespace sanitized "$sanitized" - printf -v "$var" '%s' "$sanitized" + local var=${1:?} text=${2:-} sanitized + __bp_trim_whitespace sanitized "$text" + sanitized=${sanitized%;} + sanitized=${sanitized#;} + __bp_trim_whitespace sanitized "$sanitized" + printf -v "$var" '%s' "$sanitized" } # This function is installed as part of the PROMPT_COMMAND; # It sets a variable to indicate that the prompt was just displayed, # to allow the DEBUG trap to know that the next command is likely interactive. __bp_interactive_mode() { - __bp_preexec_interactive_mode="on"; + __bp_preexec_interactive_mode="on" } - # This function is installed as part of the PROMPT_COMMAND. # It will invoke any functions defined in the precmd_functions array. __bp_precmd_invoke_cmd() { - # Save the returned value from our last command, and from each process in - # its pipeline. Note: this MUST be the first thing done in this function. - __bp_last_ret_value="$?" BP_PIPESTATUS=("${PIPESTATUS[@]}") - - # Don't invoke precmds if we are inside an execution of an "original - # prompt command" by another precmd execution loop. This avoids infinite - # recursion. - if (( __bp_inside_precmd > 0 )); then - return - fi - local __bp_inside_precmd=1 - - # Invoke every function defined in our function array. - local precmd_function - for precmd_function in "${precmd_functions[@]}"; do - - # Only execute this function if it actually exists. - # Test existence of functions with: declare -[Ff] - if type -t "$precmd_function" 1>/dev/null; then - __bp_set_ret_value "$__bp_last_ret_value" "$__bp_last_argument_prev_command" - # Quote our function invocation to prevent issues with IFS - "$precmd_function" - fi - done + # Save the returned value from our last command, and from each process in + # its pipeline. Note: this MUST be the first thing done in this function. + __bp_last_ret_value="$?" BP_PIPESTATUS=("${PIPESTATUS[@]}") + + # Don't invoke precmds if we are inside an execution of an "original + # prompt command" by another precmd execution loop. This avoids infinite + # recursion. + if ((__bp_inside_precmd > 0)); then + return + fi + local __bp_inside_precmd=1 + + # Invoke every function defined in our function array. + local precmd_function + for precmd_function in "${precmd_functions[@]}"; do + + # Only execute this function if it actually exists. + # Test existence of functions with: declare -[Ff] + if type -t "$precmd_function" 1> /dev/null; then + __bp_set_ret_value "$__bp_last_ret_value" "$__bp_last_argument_prev_command" + # Quote our function invocation to prevent issues with IFS + "$precmd_function" + fi + done } # Sets a return value in $?. We may want to get access to the $? variable in our # precmd functions. This is available for instance in zsh. We can simulate it in bash # by setting the value here. __bp_set_ret_value() { - return ${1:-} + return ${1:-} } __bp_in_prompt_command() { - local prompt_command_array - IFS=$'\n;' read -rd '' -a prompt_command_array <<< "${PROMPT_COMMAND:-}" + local prompt_command_array + IFS=$'\n;' read -rd '' -a prompt_command_array <<< "${PROMPT_COMMAND:-}" - local trimmed_arg - __bp_trim_whitespace trimmed_arg "${1:-}" + local trimmed_arg + __bp_trim_whitespace trimmed_arg "${1:-}" - local command trimmed_command - for command in "${prompt_command_array[@]:-}"; do - __bp_trim_whitespace trimmed_command "$command" - if [[ "$trimmed_command" == "$trimmed_arg" ]]; then - return 0 - fi - done + local command trimmed_command + for command in "${prompt_command_array[@]:-}"; do + __bp_trim_whitespace trimmed_command "$command" + if [[ "$trimmed_command" == "$trimmed_arg" ]]; then + return 0 + fi + done - return 1 + return 1 } # This function is installed as the DEBUG trap. It is invoked before each @@ -190,162 +188,162 @@ __bp_in_prompt_command() { # interactively, and invoke 'preexec' if so. __bp_preexec_invoke_exec() { - # Save the contents of $_ so that it can be restored later on. - # https://stackoverflow.com/questions/40944532/bash-preserve-in-a-debug-trap#40944702 - __bp_last_argument_prev_command="${1:-}" - # Don't invoke preexecs if we are inside of another preexec. - if (( __bp_inside_preexec > 0 )); then - return - fi - local __bp_inside_preexec=1 - - # Checks if the file descriptor is not standard out (i.e. '1') - # __bp_delay_install checks if we're in test. Needed for bats to run. - # Prevents preexec from being invoked for functions in PS1 - if [[ ! -t 1 && -z "${__bp_delay_install:-}" ]]; then - return - fi - - if [[ -n "${COMP_LINE:-}" ]]; then - # We're in the middle of a completer. This obviously can't be - # an interactively issued command. - return - fi - if [[ -z "${__bp_preexec_interactive_mode:-}" ]]; then - # We're doing something related to displaying the prompt. Let the - # prompt set the title instead of me. - return - else - # If we're in a subshell, then the prompt won't be re-displayed to put - # us back into interactive mode, so let's not set the variable back. - # In other words, if you have a subshell like - # (sleep 1; sleep 2) - # You want to see the 'sleep 2' as a set_command_title as well. - if [[ 0 -eq "${BASH_SUBSHELL:-}" ]]; then - __bp_preexec_interactive_mode="" - fi - fi - - if __bp_in_prompt_command "${BASH_COMMAND:-}"; then - # If we're executing something inside our prompt_command then we don't - # want to call preexec. Bash prior to 3.1 can't detect this at all :/ - __bp_preexec_interactive_mode="" - return - fi - - local this_command - this_command=$( - export LC_ALL=C - HISTTIMEFORMAT= builtin history 1 | sed '1 s/^ *[0-9][0-9]*[* ] //' - ) - - # Sanity check to make sure we have something to invoke our function with. - if [[ -z "$this_command" ]]; then - return - fi - - # Invoke every function defined in our function array. - local preexec_function - local preexec_function_ret_value - local preexec_ret_value=0 - for preexec_function in "${preexec_functions[@]:-}"; do - - # Only execute each function if it actually exists. - # Test existence of function with: declare -[fF] - if type -t "$preexec_function" 1>/dev/null; then - __bp_set_ret_value ${__bp_last_ret_value:-} - # Quote our function invocation to prevent issues with IFS - "$preexec_function" "$this_command" - preexec_function_ret_value="$?" - if [[ "$preexec_function_ret_value" != 0 ]]; then - preexec_ret_value="$preexec_function_ret_value" - fi - fi - done - - # Restore the last argument of the last executed command, and set the return - # value of the DEBUG trap to be the return code of the last preexec function - # to return an error. - # If `extdebug` is enabled a non-zero return value from any preexec function - # will cause the user's command not to execute. - # Run `shopt -s extdebug` to enable - __bp_set_ret_value "$preexec_ret_value" "$__bp_last_argument_prev_command" + # Save the contents of $_ so that it can be restored later on. + # https://stackoverflow.com/questions/40944532/bash-preserve-in-a-debug-trap#40944702 + __bp_last_argument_prev_command="${1:-}" + # Don't invoke preexecs if we are inside of another preexec. + if ((__bp_inside_preexec > 0)); then + return + fi + local __bp_inside_preexec=1 + + # Checks if the file descriptor is not standard out (i.e. '1') + # __bp_delay_install checks if we're in test. Needed for bats to run. + # Prevents preexec from being invoked for functions in PS1 + if [[ ! -t 1 && -z "${__bp_delay_install:-}" ]]; then + return + fi + + if [[ -n "${COMP_LINE:-}" ]]; then + # We're in the middle of a completer. This obviously can't be + # an interactively issued command. + return + fi + if [[ -z "${__bp_preexec_interactive_mode:-}" ]]; then + # We're doing something related to displaying the prompt. Let the + # prompt set the title instead of me. + return + else + # If we're in a subshell, then the prompt won't be re-displayed to put + # us back into interactive mode, so let's not set the variable back. + # In other words, if you have a subshell like + # (sleep 1; sleep 2) + # You want to see the 'sleep 2' as a set_command_title as well. + if [[ 0 -eq "${BASH_SUBSHELL:-}" ]]; then + __bp_preexec_interactive_mode="" + fi + fi + + if __bp_in_prompt_command "${BASH_COMMAND:-}"; then + # If we're executing something inside our prompt_command then we don't + # want to call preexec. Bash prior to 3.1 can't detect this at all :/ + __bp_preexec_interactive_mode="" + return + fi + + local this_command + this_command=$( + export LC_ALL=C + HISTTIMEFORMAT= builtin history 1 | sed '1 s/^ *[0-9][0-9]*[* ] //' + ) + + # Sanity check to make sure we have something to invoke our function with. + if [[ -z "$this_command" ]]; then + return + fi + + # Invoke every function defined in our function array. + local preexec_function + local preexec_function_ret_value + local preexec_ret_value=0 + for preexec_function in "${preexec_functions[@]:-}"; do + + # Only execute each function if it actually exists. + # Test existence of function with: declare -[fF] + if type -t "$preexec_function" 1> /dev/null; then + __bp_set_ret_value ${__bp_last_ret_value:-} + # Quote our function invocation to prevent issues with IFS + "$preexec_function" "$this_command" + preexec_function_ret_value="$?" + if [[ "$preexec_function_ret_value" != 0 ]]; then + preexec_ret_value="$preexec_function_ret_value" + fi + fi + done + + # Restore the last argument of the last executed command, and set the return + # value of the DEBUG trap to be the return code of the last preexec function + # to return an error. + # If `extdebug` is enabled a non-zero return value from any preexec function + # will cause the user's command not to execute. + # Run `shopt -s extdebug` to enable + __bp_set_ret_value "$preexec_ret_value" "$__bp_last_argument_prev_command" } __bp_install() { - # Exit if we already have this installed. - if [[ "${PROMPT_COMMAND:-}" == *"__bp_precmd_invoke_cmd"* ]]; then - return 1; - fi - - trap '__bp_preexec_invoke_exec "$_"' DEBUG - - # Preserve any prior DEBUG trap as a preexec function - local prior_trap=$(sed "s/[^']*'\(.*\)'[^']*/\1/" <<<"${__bp_trap_string:-}") - unset __bp_trap_string - if [[ -n "$prior_trap" ]]; then - eval '__bp_original_debug_trap() { + # Exit if we already have this installed. + if [[ "${PROMPT_COMMAND:-}" == *"__bp_precmd_invoke_cmd"* ]]; then + return 1 + fi + + trap '__bp_preexec_invoke_exec "$_"' DEBUG + + # Preserve any prior DEBUG trap as a preexec function + local prior_trap=$(sed "s/[^']*'\(.*\)'[^']*/\1/" <<< "${__bp_trap_string:-}") + unset __bp_trap_string + if [[ -n "$prior_trap" ]]; then + eval '__bp_original_debug_trap() { '"$prior_trap"' }' - preexec_functions+=(__bp_original_debug_trap) - fi - - # Adjust our HISTCONTROL Variable if needed. - __bp_adjust_histcontrol - - # Issue #25. Setting debug trap for subshells causes sessions to exit for - # backgrounded subshell commands (e.g. (pwd)& ). Believe this is a bug in Bash. - # - # Disabling this by default. It can be enabled by setting this variable. - if [[ -n "${__bp_enable_subshells:-}" ]]; then - - # Set so debug trap will work be invoked in subshells. - set -o functrace > /dev/null 2>&1 - shopt -s extdebug > /dev/null 2>&1 - fi; - - local existing_prompt_command - # Remove setting our trap install string and sanitize the existing prompt command string - existing_prompt_command="${PROMPT_COMMAND:-}" - existing_prompt_command="${existing_prompt_command//$__bp_install_string[;$'\n']}" # Edge case of appending to PROMPT_COMMAND - existing_prompt_command="${existing_prompt_command//$__bp_install_string}" - __bp_sanitize_string existing_prompt_command "$existing_prompt_command" - - # Install our hooks in PROMPT_COMMAND to allow our trap to know when we've - # actually entered something. - PROMPT_COMMAND=$'__bp_precmd_invoke_cmd\n' - if [[ -n "$existing_prompt_command" ]]; then - PROMPT_COMMAND+=${existing_prompt_command}$'\n' - fi; - PROMPT_COMMAND+='__bp_interactive_mode' - - # Add two functions to our arrays for convenience - # of definition. - precmd_functions+=(precmd) - preexec_functions+=(preexec) - - # Invoke our two functions manually that were added to $PROMPT_COMMAND - __bp_precmd_invoke_cmd - __bp_interactive_mode + preexec_functions+=(__bp_original_debug_trap) + fi + + # Adjust our HISTCONTROL Variable if needed. + __bp_adjust_histcontrol + + # Issue #25. Setting debug trap for subshells causes sessions to exit for + # backgrounded subshell commands (e.g. (pwd)& ). Believe this is a bug in Bash. + # + # Disabling this by default. It can be enabled by setting this variable. + if [[ -n "${__bp_enable_subshells:-}" ]]; then + + # Set so debug trap will work be invoked in subshells. + set -o functrace > /dev/null 2>&1 + shopt -s extdebug > /dev/null 2>&1 + fi + + local existing_prompt_command + # Remove setting our trap install string and sanitize the existing prompt command string + existing_prompt_command="${PROMPT_COMMAND:-}" + existing_prompt_command="${existing_prompt_command//$__bp_install_string[;$'\n']/}" # Edge case of appending to PROMPT_COMMAND + existing_prompt_command="${existing_prompt_command//$__bp_install_string/}" + __bp_sanitize_string existing_prompt_command "$existing_prompt_command" + + # Install our hooks in PROMPT_COMMAND to allow our trap to know when we've + # actually entered something. + PROMPT_COMMAND=$'__bp_precmd_invoke_cmd\n' + if [[ -n "$existing_prompt_command" ]]; then + PROMPT_COMMAND+=${existing_prompt_command}$'\n' + fi + PROMPT_COMMAND+='__bp_interactive_mode' + + # Add two functions to our arrays for convenience + # of definition. + precmd_functions+=(precmd) + preexec_functions+=(preexec) + + # Invoke our two functions manually that were added to $PROMPT_COMMAND + __bp_precmd_invoke_cmd + __bp_interactive_mode } # Sets an installation string as part of our PROMPT_COMMAND to install # after our session has started. This allows bash-preexec to be included # at any point in our bash profile. __bp_install_after_session_init() { - # bash-preexec needs to modify these variables in order to work correctly - # if it can't, just stop the installation - __bp_require_not_readonly PROMPT_COMMAND HISTCONTROL HISTTIMEFORMAT || return - - local sanitized_prompt_command - __bp_sanitize_string sanitized_prompt_command "${PROMPT_COMMAND:-}" - if [[ -n "$sanitized_prompt_command" ]]; then - PROMPT_COMMAND=${sanitized_prompt_command}$'\n' - fi; - PROMPT_COMMAND+=${__bp_install_string} + # bash-preexec needs to modify these variables in order to work correctly + # if it can't, just stop the installation + __bp_require_not_readonly PROMPT_COMMAND HISTCONTROL HISTTIMEFORMAT || return + + local sanitized_prompt_command + __bp_sanitize_string sanitized_prompt_command "${PROMPT_COMMAND:-}" + if [[ -n "$sanitized_prompt_command" ]]; then + PROMPT_COMMAND=${sanitized_prompt_command}$'\n' + fi + PROMPT_COMMAND+=${__bp_install_string} } # Run our install so long as we're not delaying it. if [[ -z "${__bp_delay_install:-}" ]]; then - __bp_install_after_session_init -fi; + __bp_install_after_session_init +fi diff --git a/vendor/github.com/rparree/jboss-bash-completion/README.md b/vendor/github.com/rparree/jboss-bash-completion/README.md index 2c1b885119..96abbf6bb3 100644 --- a/vendor/github.com/rparree/jboss-bash-completion/README.md +++ b/vendor/github.com/rparree/jboss-bash-completion/README.md @@ -33,5 +33,3 @@ RHEL/CentOS: `yum install bash-completion` Copy the file(s) to your `/etc/bash_completion.d` folder: `sudo cp jboss* /etc/bash_completion.d` - - diff --git a/vendor/github.com/rparree/jboss-bash-completion/jboss5 b/vendor/github.com/rparree/jboss-bash-completion/jboss5 index aae4ff5511..6f37f49985 100644 --- a/vendor/github.com/rparree/jboss-bash-completion/jboss5 +++ b/vendor/github.com/rparree/jboss-bash-completion/jboss5 @@ -29,13 +29,13 @@ _bindingAddress5(){ _jboss5() { - + local cur prev words cword COMPREPLY=() _get_comp_words_by_ref -n = cur prev words cword - + case $cur in - + -Djboss.service.binding.set=*) cur=${cur#*=} #static list of common bindings sets @@ -84,12 +84,12 @@ _jboss5() ;; esac - + COMPREPLY=( $( compgen -W ' -u -c -m - -b -g -l -d -p -n -B -L -C -P -v -help -Djboss.platform.mbeanserver' -- "$cur" ) \ $( compgen -W '-Djboss.Domain -Djboss.modcluster.proxyList -Djboss.service.binding.set -Djboss.jvmRoute -Djboss.messaging.ServerPeerID -Djboss.default.jgroups.stack -Dorg.jboss.ejb3.remoting.IsLocalInterceptor.passByRef -Djboss.platform.mbeanserver -Dcom.sun.management.jmxremote.port -Dcom.sun.management.jmxremote.ssl' \ - -S '=' -- "$cur" ) ) + -S '=' -- "$cur" ) ) return 0 - + } complete -o nospace -F _jboss5 run.sh diff --git a/vendor/github.com/rparree/jboss-bash-completion/jboss7 b/vendor/github.com/rparree/jboss-bash-completion/jboss7 index 66d07179fd..0bb44f1511 100644 --- a/vendor/github.com/rparree/jboss-bash-completion/jboss7 +++ b/vendor/github.com/rparree/jboss-bash-completion/jboss7 @@ -14,17 +14,17 @@ _serverProfiles(){ # assume is domain.sh serverdir="../domain/configuration/" fi - + for i in ${!COMP_WORDS[*]} do if [[ "${COMP_WORDS[i]}" == "-Djboss.server.base.dir" || "${COMP_WORDS[i]}" == "-Djboss.domain.base.dir" ]]; then serverdir="${COMP_WORDS[i+2]}/configuration" - fi - + fi + done if [ -d "${serverdir}" ] then - + IFS=$'\n' tmp="$(ls "${serverdir}" | grep xml)" local fls="${tmp[@]// /\ }" unset IFS @@ -42,13 +42,13 @@ _bindingAddress(){ } _jboss(){ - + local cur prev words cword COMPREPLY=() _get_comp_words_by_ref -n = cur prev words cword - + case $cur in - + -Djboss.socket.binding.port-offset=*) cur=${cur#*=} #static list of common bindings sets @@ -70,13 +70,13 @@ _jboss(){ COMPREPLY=( $(compgen -W "${booleans}" -- ${cur}) ) return 0 ;; - + -Djboss.server.base.dir=*|-Djboss.home.dir=*|-Djboss.domain.base.dir=*) cur=${cur#*=} _filedir -d return 0 ;; - + -Djboss.domain.master.address=*|-Djboss.bind.address*=*) cur=${cur#*=} _bindingAddress @@ -85,8 +85,8 @@ _jboss(){ --server-config=*|-c=|--host-config=*) cur=${cur#*=} _serverProfiles - return 0 - + return 0 + esac @@ -110,14 +110,14 @@ _jboss(){ ;; esac # *** from jboss5 ******************** - # *** -modulepath -c -m -g -l -d -p -n -B -L -C -Djboss.platform.mbeanserver -Djboss.server.base.directory + # *** -modulepath -c -m -g -l -d -p -n -B -L -C -Djboss.platform.mbeanserver -Djboss.server.base.directory # *** -Djboss.Domain -Djboss.modcluster.proxyList -Djboss.jvmRoute -Djboss.default.jgroups.stack -Dorg.jboss.ejb3.remoting.IsLocalInterceptor.passByRef -Djboss.platform.mbeanserver -Dcom.sun.management.jmxremote.port -Dcom.sun.management.jmxremote.ssl # ************************************* - + # standard commands for standalone and domain mode local commandsWithoutEqualSign='-b -bmanagement -bunsecure -bpublic --admin-only -h -help -u -version -V -v' local commandsWithEqualSign='-P -Djboss.node.name -Djboss.home.dir -Djboss.socket.binding.port-offset -Djboss.bind.address.management -Djboss.bind.address -Djboss.bind.address.unsecure' - + if [[ $COMP_WORDS == *standalone.sh* ]] then commandsWithoutEqualSign="${commandsWithoutEqualSign} -c" @@ -127,15 +127,15 @@ _jboss(){ commandsWithoutEqualSign="${commandsWithoutEqualSign} --backup --cached-dc" commandsWithEqualSign="${commandsWithEqualSign} -Djboss.domain.master.address --host-config -Djboss.domain.master.port -Djboss.domain.base.dir " fi - - - - COMPREPLY=( $( compgen -W "$commandsWithoutEqualSign" -- "$cur" ) - $( compgen -W "$commandsWithEqualSign" -S '=' -- "$cur" ) ) + + + + COMPREPLY=( $( compgen -W "$commandsWithoutEqualSign" -- "$cur" ) + $( compgen -W "$commandsWithEqualSign" -S '=' -- "$cur" ) ) return 0 - + } complete -o nospace -F _jboss standalone.sh complete -o nospace -F _jboss domain.sh diff --git a/vendor/github.com/vigo/apm-bash-completion/CODE_OF_CONDUCT.md b/vendor/github.com/vigo/apm-bash-completion/CODE_OF_CONDUCT.md index db8700e44b..35116ddc1e 100644 --- a/vendor/github.com/vigo/apm-bash-completion/CODE_OF_CONDUCT.md +++ b/vendor/github.com/vigo/apm-bash-completion/CODE_OF_CONDUCT.md @@ -73,4 +73,4 @@ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.ht [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see -https://www.contributor-covenant.org/faq \ No newline at end of file +https://www.contributor-covenant.org/faq