Last active
February 25, 2022 09:18
-
-
Save ryran/dc0ec41ae5311ac40ce2896d19bbc984 to your computer and use it in GitHub Desktop.
Revisions
-
ryran revised this gist
Feb 25, 2022 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -66,11 +66,11 @@ precmd_powerline_prompt() { # This command is used to manage the powerline-go in PS1, on-the-fly pwr() { local me=${FUNCNAME[0]} local arg= x= __need_to_add local usage=$(cat <<-EOF Usage: $me [0 | off] or: $me [1 | on] [r[eset] | d[efault]] [-t | -time] [-u | -user] [-H | -host] [-c | -cwd] [-g | -git] [-e | -exit] [-r | -root] [-d | -duration] [paths+=ALIAS | paths=[ALIAS][,ALIAS]...] [tz=[TZ]] [theme=[THEME]] [newline=[y]] [cwd=[MODE]] [git=[MODE]] [host=[ssh]] EOF @@ -102,6 +102,7 @@ pwr() { -t|-time Disable time module (don't show the current time) -u|-user Disable user module (don't show username) -H|-host Disable host module (don't show hostname) -c|-cwd Disable cwd module (don't show CWD) -g|-git Disable git module (don't show git info when in a git proj) -e|-exit Disable exit module (don't show error codes) @@ -145,6 +146,7 @@ pwr() { $me originally created by rsaw, aka ryran, as "pwr" https://gist.github.com/ryran/dc0ec41ae5311ac40ce2896d19bbc984 EOF return 1 fi # Process off/on/reset/default before any other args for arg in $@; do case $arg in @@ -165,6 +167,7 @@ pwr() { case $1 in -t|-time) x=${__pwr_mods/time} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; -u|-user) x=${__pwr_mods/user} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; -H|-host) x=${__pwr_mods/host} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; -c|-cwd) x=${__pwr_mods/cwd} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; -g|-git) x=${__pwr_mods/git} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; -e|-exit) x=${__pwr_mods/exit} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; -
ryran revised this gist
Feb 24, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ # powerline-go for PS1, customizable-on-the-fly thanks to bash-preexec & a custom helper function # https://gist.github.com/ryran/dc0ec41ae5311ac40ce2896d19bbc984 # Source from the bottom of ~/.bashrc # Backup PS1 [[ $PS1_ORIG ]] || PS1_ORIG=$PS1 -
ryran revised this gist
Feb 24, 2022 . 1 changed file with 9 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,15 @@ # powerline-go for PS1, customizable-on-the-fly thanks to bash-preexec & a custom helper function # https://gist.github.com/ryran/dc0ec41ae5311ac40ce2896d19bbc984 # Backup PS1 [[ $PS1_ORIG ]] || PS1_ORIG=$PS1 # Download binary from github.com/justjanne/powerline-go & customize the path here __pwr_binpath=/usr/local/bin/powerline-go # Clone github.com/rcaloras/bash-preexec & customize the path here # We use this to plug powerline-go into the shell PS1 __bash_preexec_path=/usr/local/lib/bash-preexec.sh # Need to be able to grab default powerline-go modules cfg from help page __pwr_mods_get_default() { $__pwr_binpath -h 2>&1 | awk '/^ -modules string/,/default/' | grep -F '(default "' | cut -d\" -f2; } @@ -26,12 +24,12 @@ __pwr_get_valid_gitmodes() { $__pwr_binpath -h 2>&1 | awk '/^ -git-mode string/ # Check the "pwr -h" help page in order to compare this with powerline-go's default # Notable ommissions that might bother you & which you might want to remedy: # "user" (your username) & "root" (the $ or # indicating root user) __pwr_mods_my_default='time,ssh,user,host,shell-var,venv,cwd,perms,git,jobs,exit,duration' # Next is the variable that's actually used for PS1, so if you want to experiment # with modules & their ordering, you could modify this from an interactive shell __pwr_mods=${__pwr_mods_my_default} # Replace my custom path alias examples with any of your own, comma-delimited __pwr_path_aliases='-path-aliases /often/used/path/to/dir=short-dir-alias,/a/b/c/d=abcd' # Custom TZ __pwr_tz= # Custom theme @@ -45,7 +43,8 @@ __pwr_git_mode='-git-mode fancy' # Whether to only display hostname if ssh __pwr_hostname_if_ssh='-hostname-only-if-ssh' # Customize as needed: __pwr_extra_opts='-shell bash -colorize-hostname -numeric-exit-codes -shell-var-no-warn-empty -shell-var OS_CLOUDNAME' export OS_CLOUDNAME=$OS_CLOUDNAME # You can enable/disable all of bash-preexec at any time via shell var PREEXEC={0|1} : ${PREEXEC:=1} @@ -214,4 +213,4 @@ if [[ $PREEXEC == 1 ]]; then else pwr off unset -f preexec precmd preexec_functions precmd_functions fi -
ryran revised this gist
Dec 16, 2021 . 1 changed file with 2 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,7 @@ # powerline-go for PS1, customizable-on-the-fly thanks to bash-preexec & a custom helper function # https://gist.github.com/ryran/dc0ec41ae5311ac40ce2896d19bbc984 # Add to the bottom of ~/.bashrc # Or put in a separate file and source from the bottom of ~/.bashrc # Backup PS1 [[ $PS1_ORIG ]] || PS1_ORIG=$PS1 -
ryran revised this gist
Mar 18, 2021 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,10 +11,10 @@ fi # Backup PS1 [[ $PS1_ORIG ]] || PS1_ORIG=$PS1 # Clone github.com/justjanne/powerline-go or download binary & customize the path here __pwr_binpath=~/bin/powerline-go # Clone github.com/rcaloras/bash-preexec & customize the path here # We use this to plug powerline-go into the shell PS1 __bash_preexec_path=/g/bash-preexec/bash-preexec.sh @@ -31,7 +31,7 @@ __pwr_get_valid_gitmodes() { $__pwr_binpath -h 2>&1 | awk '/^ -git-mode string/ # Check the "pwr -h" help page in order to compare this with powerline-go's default # Notable ommissions that might bother you & which you might want to remedy: # "user" (your username) & "root" (the $ or # indicating root user) __pwr_mods_my_default='time,ssh,host,venv,cwd,perms,git,jobs,exit,duration' # Next is the variable that's actually used for PS1, so if you want to experiment # with modules & their ordering, you could modify this from an interactive shell __pwr_mods=${__pwr_mods_my_default} -
ryran revised this gist
Mar 12, 2021 . 1 changed file with 123 additions and 52 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,9 @@ if [ -f /etc/bashrc ]; then . /etc/bashrc fi # powerline-go for PS1, customizable-on-the-fly thanks to bash-preexec & a custom helper function # https://gist.github.com/ryran/dc0ec41ae5311ac40ce2896d19bbc984 # Backup PS1 [[ $PS1_ORIG ]] || PS1_ORIG=$PS1 @@ -16,18 +19,38 @@ __pwr_binpath=~/bin/powerline-go __bash_preexec_path=/g/bash-preexec/bash-preexec.sh # Need to be able to grab default powerline-go modules cfg from help page __pwr_mods_get_default() { $__pwr_binpath -h 2>&1 | awk '/^ -modules string/,/default/' | grep -F '(default "' | cut -d\" -f2; } # And let's also get some other stuff for our own help page __pwr_get_valid_themes() { $__pwr_binpath -h 2>&1 | awk '/^ -theme string/,/valid choices/' | grep -o '(valid choices.*'; } __pwr_get_valid_cwdmodes() { $__pwr_binpath -h 2>&1 | awk '/^ -cwd-mode string/,/valid choices/' | grep -o '(valid choices.*'; } __pwr_get_valid_gitmodes() { $__pwr_binpath -h 2>&1 | awk '/^ -git-mode string/,/valid choices/' | grep -o '(valid choices.*'; } # Define the components of powerline-go PS1 precmd function (for use w/bash-preexec) # Check the "pwr -h" help page in order to compare this with powerline-go's default # Notable ommissions that might bother you & which you might want to remedy: # "user" (your username) & "root" (the $ or # indicating root user) __pwr_mods_my_default='time,venv,host,ssh,cwd,perms,git,jobs,exit,duration' # Next is the variable that's actually used for PS1, so if you want to experiment # with modules & their ordering, you could modify this from an interactive shell __pwr_mods=${__pwr_mods_my_default} # Remove my custom path alias and add any of your own, comma-delimited __pwr_path_aliases='-path-aliases /g/x/git=x' # Custom TZ __pwr_tz= # Custom theme __pwr_theme='-theme default' # Whether to use --newline __pwr_newline= # Custom cwd-mode __pwr_cwd_mode='-cwd-mode fancy' # Custom git-mode __pwr_git_mode='-git-mode fancy' # Whether to only display hostname if ssh __pwr_hostname_if_ssh='-hostname-only-if-ssh' # Customize as needed: __pwr_extra_opts='-shell bash -colorize-hostname' # You can enable/disable all of bash-preexec at any time via shell var PREEXEC={0|1} : ${PREEXEC:=1} @@ -37,96 +60,144 @@ __pwr_extra_opts='-shell bash -hostname-only-if-ssh -colorize-hostname' precmd_powerline_prompt() { # Shouldn't need to customize this unless you want to get rid of checking of background-jobs local rc=$? if [[ -x $__pwr_binpath ]] && [[ $PWR == 1 || $PWR == on ]]; then PS1=$( [[ $__pwr_tz ]] && export TZ=$__pwr_tz; $__pwr_binpath -error $rc -duration $((SECONDS - __CMD_START)) -jobs $(jobs -p | wc -l) $__pwr_path_aliases $__pwr_theme $__pwr_newline $__pwr_cwd_mode $__pwr_git_mode $__pwr_hostname_if_ssh -modules $__pwr_mods $__pwr_extra_opts ) else PS1=$PS1_ORIG fi } # This command is used to manage the powerline-go in PS1, on-the-fly pwr() { local me=${FUNCNAME[0]} local arg= x= __need_to_add local usage=$(cat <<-EOF Usage: $me [0 | off] or: $me [1 | on] [r[eset] | d[efault]] [-d | -duration] [-t | -time] [-u | -user] [-c | -cwd] [-g | -git] [-e | -exit] [-r | -root] [paths+=ALIAS | paths=[ALIAS][,ALIAS]...] [tz=[TZ]] [theme=[THEME]] [newline=[y]] [cwd=[MODE]] [git=[MODE]] [host=[ssh]] EOF ) if [[ $# == 0 || $1 == -h || $1 == --help ]]; then echo "$usage" cat <<-EOF Control & configure powerline-go integrated into current shell's PS1 prompt 0|off Completely disable powerline-go prompt Alternatively: set shell var PWR=0 1|on If powerline-go prompt disabled, enable it Alternatively: set shell var PWR=1 r|reset Reset modules to custom defaults defined in the shell var "__pwr_mods_my_default", i.e.: $__pwr_mods_my_default To make permanent changes, update that var in bashrc d|default Reset modules to powerline-go's built-in defaults, extracted from the help page, i.e.: $( __pwr_mods_get_default ) Use the following to disable specific modules in current shell. (Can be used in concert with "on", "reset", and "default".) -t|-time Disable time module (don't show the current time) -u|-user Disable user module (don't show username) -c|-cwd Disable cwd module (don't show CWD) -g|-git Disable git module (don't show git info when in a git proj) -e|-exit Disable exit module (don't show error codes) -r|-root Disable root module (don't show "$" or "#") -d|-duration Disable duration module (don't show elapsed time) Use the following args to tweak other bits of the prompt in current shell. To make changes permanent, update the corresponding shell cfg variable (listed underneath each option) in bashrc. To reset any of these to powerline-go's built-in default, use "--OPTION=", i.e., equals sign w/ no arg. paths+=ALIAS paths=[ALIAS][,ALIAS]... Add new path alias in the form /DIR=NAME or define a comma- delimited list of path aliases or get rid of them all (current setting: "${__pwr_path_aliases#-path-aliases}") \$__pwr_path_aliases tz=[TZ] Set timezone used by time module \$__pwr_tz theme=[THEME] Modify theme $( __pwr_get_valid_themes ) \$__pwr_theme newline=[y] Show the prompt on a new line \$__pwr_newline cwd=[MODE] Change how cwd module displays current dir $( __pwr_get_valid_cwdmodes ) \$__pwr_cwd_mode git=MODE Change how git module displays status $( __pwr_get_valid_gitmodes ) \$__pwr_git_mode host=[ssh] Modify host module to only show hostname if ssh Use "--host=" to reset to always showing hostname \$__pwr_hostname_if_ssh $me originally created by rsaw, aka ryran, as "pwr" https://gist.github.com/ryran/dc0ec41ae5311ac40ce2896d19bbc984 EOF fi # Process off/on/reset/default before any other args for arg in $@; do case $arg in 0|off) PWR=0; return ;; 1|on) # only reset if this is completely unset [[ $__pwr_mods ]] || __pwr_mods=$__pwr_mods_my_default PWR=1 ;; r|reset) __pwr_mods=$__pwr_mods_my_default ;; d|default) __pwr_mods=$( __pwr_mods_get_default ) ;; *) continue esac; done until [[ $# == 0 ]]; do case $1 in -t|-time) x=${__pwr_mods/time} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; -u|-user) x=${__pwr_mods/user} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; -c|-cwd) x=${__pwr_mods/cwd} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; -g|-git) x=${__pwr_mods/git} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; -e|-exit) x=${__pwr_mods/exit} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; -r|-root) x=${__pwr_mods/root} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; -d|-duration) x=${__pwr_mods/duration} x=${x#,} x=${x%,} __pwr_mods=${x/,,/,} ;; 1|on|r|reset|d|default) # Already processed above : ;; paths+=*) arg=${1#paths+=} [[ $__pwr_path_aliases ]] && __pwr_path_aliases+=,$arg || __pwr_path_aliases="-path-aliases $arg" ;; paths=*) arg=${1#paths=} [[ $arg ]] && __pwr_path_aliases="-path-aliases $arg" || __pwr_path_aliases= ;; tz=*) __pwr_tz=${1#tz=} ;; theme=*) arg=${1#theme=}; [[ $arg ]] && __pwr_theme="-theme $arg" || __pwr_theme= ;; newline=*) [[ ${1#newline=} == y ]] && __pwr_newline=--newline || __pwr_newline= ;; cwd=*) arg=${1#cwd=}; [[ $arg ]] && __pwr_cwd_mode="-cwd-mode $arg" || __pwr_cwd_mode= ;; git=*) arg=${1#git=}; [[ $arg ]] && __pwr_git_mode="-git-mode $arg" || __pwr_git_mode= ;; host=*) [[ ${1#host=} == ssh ]] && __pwr_hostname_if_ssh=-hostname-only-if-ssh || __pwr_hostname_if_ssh= ;; *) echo -e "ERROR: unsupported arg \"$1\"\n\n$usage" return 2 esac shift done if [[ $PWR == 1 || $PWR == on ]] && [[ $TERM != linux ]]; then __need_to_add=1 for func in ${precmd_functions[@]}; do [[ $func == precmd_powerline_prompt ]] && __need_to_add= done -
ryran revised this gist
Mar 8, 2021 . 1 changed file with 5 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,7 @@ __pwr_extra_opts='-shell bash -hostname-only-if-ssh -colorize-hostname' precmd_powerline_prompt() { # Shouldn't need to customize this unless you want to get rid of checking of background-jobs if [[ -x $__pwr_binpath ]] && [[ $PWR == 1 || $PWR == on ]]; then PS1=$( $__pwr_binpath -error $? -duration $((SECONDS - __CMD_START)) -jobs $(jobs -p | wc -l) -modules $__pwr_mods $__pwr_path_aliases $__pwr_extra_opts ) else PS1=$PS1_ORIG @@ -55,7 +55,7 @@ pwr() { Alternatively: set shell var PWR=0 1|on If powerline-go prompt disabled, enable it Alternatively: set shell var PWR=1 Usage: pwr [-duration] [-time] [-user] [-cwd] [-git] [-exit] [-root] Remove specific modules from powerline-go in current shell's PS1 prompt @@ -125,16 +125,14 @@ pwr() { esac shift done if [[ $PWR == 1 || $PWR == on ]] && [[ $TERM != linux ]]; then local __need_to_add=1 for func in ${precmd_functions[@]}; do [[ $func == precmd_powerline_prompt ]] && __need_to_add= done [[ $__need_to_add ]] && precmd_functions+=( precmd_powerline_prompt ) fi return 0 } # Enable or disable bash-preexec based on $PREEXEC @@ -150,4 +148,4 @@ if [[ $PREEXEC == 1 ]]; then else pwr off unset -f preexec precmd preexec_functions precmd_functions fi -
ryran revised this gist
Mar 8, 2021 . 2 changed files with 153 additions and 113 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,153 @@ # This is the top of my .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # Backup PS1 [[ $PS1_ORIG ]] || PS1_ORIG=$PS1 # Clone github.com/justjanne/powerline-go and customize the path here __pwr_binpath=~/bin/powerline-go # Clone github.com/rcaloras/bash-preexec and customize the path here # We use this to plug powerline-go into the shell PS1 __bash_preexec_path=/g/bash-preexec/bash-preexec.sh # Need to be able to grab default powerline-go modules cfg from help page __pwr_mods_get_default() { $__pwr_binpath -h 2>&1 | awk '/^ -modules string/,/default/' | grep -F '(default "' | cut -d\" -f2 } # Define the components of powerline-go PS1 precmd function (for use w/bash-preexec) # Once you've tried it out, you can come back and customize this __pwr_mods_my_default='duration,time,venv,host,ssh,cwd,perms,git,jobs,exit' __pwr_mods=${__pwr_mods_my_default} # Add any path aliases here __pwr_path_aliases='-path-aliases /g/x/git=xgit' # Customize as needed: __pwr_extra_opts='-shell bash -hostname-only-if-ssh -colorize-hostname' # You can enable/disable all of bash-preexec at any time via shell var PREEXEC={0|1} : ${PREEXEC:=1} # You can enable/disable powerline-go prompt at any time via shell var PWR={0|1} : ${PWR:=1} precmd_powerline_prompt() { # Shouldn't need to customize this unless you want to get rid of checking of background-jobs if [[ $PWR == 1 || $PWR == on ]]; then PS1=$( $__pwr_binpath -error $? -duration $((SECONDS - __CMD_START)) -jobs $(jobs -p | wc -l) -modules $__pwr_mods $__pwr_path_aliases $__pwr_extra_opts ) else PS1=$PS1_ORIG fi } # This command is used to manage the powerline-go in PS1, on-the-fly pwr() { if [[ $# == 0 || $1 == -h || $1 == --help ]]; then cat <<-EOF Usage: pwr ( off | on ) Enable/disable powerline-go integrated with current shell's PS1 prompt 0|off Completely disable powerline-go prompt Alternatively: set shell var PWR=0 1|on If powerline-go prompt disabled, enable it Alternatively: set shell var PWR=1 (only if disabled via PWR=0) Usage: pwr [-duration] [-time] [-user] [-cwd] [-git] [-exit] [-root] Remove specific modules from powerline-go in current shell's PS1 prompt (These can be used in concert with "on", "reset", and "default") -d|-duration Disable duration module (don't show elapsed time) -t|-time Disable time module (don't show the current time) -u|-user Disable user module (don't show username) -c|-cwd Disable cwd module (don't show CWD; auto-enable root module) -g|-git Disable git module (don't show git info when in a git proj) -e|-exit Disable exit module (don't show error codes) -r|-root Disable root module (don't show "$" or "#") Usage: pwr ( reset | default ) Reset module cfg of powerline-go in current shell's PS1 prompt r|reset Reset modules to custom defaults, i.e.: $__pwr_mods_my_default To make permanent changes, edit \${__pwr_mods_my_default} in bashrc d|default Reset modules to powerline-go's built-in defaults, extracted from the help page, i.e.: $( __pwr_mods_get_default ) pwr originally created by rsaw, aka ryran https://gist.github.com/ryran/dc0ec41ae5311ac40ce2896d19bbc984 EOF return 1 fi # Process off/on/reset/default before any other args local arg for arg in $@; do case $arg in 0|off) PWR=0 return ;; 1|on) PWR=1 # only reset if this is completely unset [[ $__pwr_mods ]] || __pwr_mods=$__pwr_mods_my_default ;; r|reset) __pwr_mods=$__pwr_mods_my_default ;; d|default) __pwr_mods=$( __pwr_mods_get_default ) ;; *) continue esac; done until [[ $# == 0 ]]; do case $1 in -d|-duration) __pwr_mods=${__pwr_mods/duration,/} ;; -t|-time) __pwr_mods=${__pwr_mods/time,/} ;; -u|-user) __pwr_mods=${__pwr_mods/user,/} ;; -c|-cwd) __pwr_mods=${__pwr_mods/cwd,/}; [[ $__pwr_mods =~ ,root ]] || __pwr_mods+=,root ;; -g|-git) __pwr_mods=${__pwr_mods/,git/} ;; -e|-exit) __pwr_mods=${__pwr_mods/,exit/} ;; -r|-root) __pwr_mods=${__pwr_mods/,root/} ;; 1|on|r|reset|d|default) # Already processed above : ;; *) echo -e "ERROR: unsupported arg \"$1\"\n" pwr -h return 2 esac shift done if [[ $TERM != linux && -x $__pwr_binpath ]]; then PWR=1 local __need_to_add=1 for func in ${precmd_functions[@]}; do [[ $func == precmd_powerline_prompt ]] && __need_to_add= done [[ $__need_to_add ]] && precmd_functions+=( precmd_powerline_prompt ) : fi return } # Enable or disable bash-preexec based on $PREEXEC if [[ $PREEXEC == 1 ]]; then . $__bash_preexec_path # Add a simple cmd-timer that takes advantage of bash's $SECONDS var preexec_start_timer() { __CMD_START=$SECONDS; } preexec_functions+=( preexec_start_timer ) # Enable or disable powerline-go based on $PWR [[ $PWR == 1 || $PWR == on ]] && pwr on || pwr off else pwr off unset -f preexec precmd preexec_functions precmd_functions fi This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,113 +0,0 @@ -
ryran revised this gist
Mar 8, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -77,8 +77,8 @@ pwr() { -d|-duration) __pwr_mods=${__pwr_mods/duration,/} ;; -t|-time) __pwr_mods=${__pwr_mods/time,/} ;; -c|-cwd) __pwr_mods=${__pwr_mods/cwd,/}; [[ $__pwr_mods =~ ,root ]] || __pwr_mods+=,root ;; -r|-root) __pwr_mods=${__pwr_mods/,root/} ;; -e|-exit) __pwr_mods=${__pwr_mods/,exit/} ;; *) echo -e "ERROR: unsupported arg \"$1\"\n\nusage: powerline { 0 | 1 | args }\n(See -h for more detail)" return 2 -
ryran created this gist
Mar 8, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,113 @@ # This is the top of my .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # Backup PS1 [[ $PS1_ORIG ]] || PS1_ORIG=$PS1 # Clone github.com/justjanne/powerline-go and customize the path here __pwr_binpath=~/bin/powerline-go # Clone github.com/rcaloras/bash-preexec and customize the path here # We use this to plug powerline-go into the shell PS1 __bash_preexec_path=/g/bash-preexec/bash-preexec.sh # Now we define components of powerline-go PS1 precmd function (for use w/bash-preexec) # Once you've tried it out, you can come back and customize this __pwr_mods_default='duration,time,venv,host,ssh,cwd,perms,git,jobs,exit' __pwr_mods=${__pwr_mods_default} # Add any path aliases here __pwr_path_aliases='-path-aliases /g/x/git=xgit' # Customize as needed: __pwr_extra_opts='-shell bash -hostname-only-if-ssh -colorize-hostname' # You can enable/disable all of bash-preexec at any time via shell var PREEXEC={0|1} PREEXEC=1 # You can enable/disable powerline-go prompt at any time via shell var PWR={0|1} PWR=1 precmd_powerline_prompt() { # Shouldn't need to customize this unless you want to get rid of bg-job-checking PS1=$( $__pwr_binpath -error $? -duration $((SECONDS - __CMD_START)) -jobs $(jobs -p | wc -l) -modules $__pwr_mods $__pwr_path_aliases $__pwr_extra_opts ) } # This command is used to manage the powerline-go in PS1, on-the-fly pwr() { if [[ $# == 0 || $1 == -h || $1 == --help ]]; then cat <<-EOF usage: pwr { 0 | 1 | args } Control powerline-go integrated with PS1 prompt (Enable, disable, or reconfigure) args: 0 Completely disable powerline-go prompt 1 Enable powerline-go or reset to default settings -d|-duration Disable duration module (don't show elapsed time) -t|-time Disable time module (don't show the current time) -c|-cwd Disable cwd module (don't show CWD; auto-enable root module) -r|-root Disable root module (don't show "$" or "#") -e|-exit Disable exit module (don't show error codes) EOF return 1 fi until [[ $# == 0 ]]; do case $1 in 0) # remove "precmd_powerline_prompt" from precmd_functions array precmd_functions=( $(for func in ${precmd_functions[@]}; do [[ $func == precmd_powerline_prompt ]] || echo $func; done) ) PS1=$PS1_ORIG PWR=0 return ;; 1) __pwr_mods=$__pwr_mods_default ;; -d|-duration) __pwr_mods=${__pwr_mods/duration,/} ;; -t|-time) __pwr_mods=${__pwr_mods/time,/} ;; -c|-cwd) __pwr_mods=${__pwr_mods/cwd,/}; [[ $__pwr_mods =~ ,root ]] || __pwr_mods+=,root ;; -r|-root) __pwr_mods=${__pwr_mods/root,/} ;; -e|-exit) __pwr_mods=${__pwr_mods/exit,/} ;; *) echo -e "ERROR: unsupported arg \"$1\"\n\nusage: powerline { 0 | 1 | args }\n(See -h for more detail)" return 2 esac shift done if [[ $TERM != linux && -x $__pwr_binpath ]]; then PWR=1 local __need_to_add=1 for func in ${precmd_functions[@]}; do [[ $func == precmd_powerline_prompt ]] && __need_to_add= done [[ $__need_to_add ]] && precmd_functions+=( precmd_powerline_prompt ) : fi return } # Enable or disable bash-preexec based on $PREEXEC if [[ $PREEXEC == 1 ]]; then . $__bash_preexec_path # Add a simple cmd-timer that takes advantage of bash's $SECONDS var preexec_start_timer() { __CMD_START=$SECONDS; } preexec_functions+=( preexec_start_timer ) # Enable or disable powerline-go based on $PWR [[ $PWR == 1 ]] && pwr 1 || pwr 0 else pwr 0 unset -f preexec precmd preexec_functions precmd_functions fi