From b8d16027f09da7645d9e13237db47565e6146507 Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 19 Aug 2021 23:28:17 +0400 Subject: [PATCH] feat: TOOLBOX path --- bash.bashrc | 138 +++++++++++++++++++++++++++------------------------- 1 file changed, 71 insertions(+), 67 deletions(-) diff --git a/bash.bashrc b/bash.bashrc index ed6b877..7ca6253 100644 --- a/bash.bashrc +++ b/bash.bashrc @@ -2,8 +2,8 @@ # If not running interactively, don't do anything case $- in - *i*) ;; - *) return;; +*i*) ;; +*) return ;; esac # don't put duplicate lines or lines starting with space in the history. @@ -25,10 +25,10 @@ shopt -s checkwinsize # set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in - xterm-color|*-256color) - color_prompt=yes - export COLOR_OPTIONS=' --color=auto' - ;; +xterm-color | *-256color) + color_prompt=yes + export COLOR_OPTIONS=' --color=auto' + ;; esac export LS_COLORS="rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.sql.gz=01;35:*.mariadb.gz=01;35:*.postgres.gz=01;35:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=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;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=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:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=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:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:" @@ -45,9 +45,8 @@ if ! shopt -oq posix; then fi fi - __prompt_command() { - local EXIT="$?" # This needs to be first + local EXIT="$?" # This needs to be first local R='\[\e[0m\]' local Red='\[\e[1;31m\]' @@ -59,26 +58,27 @@ __prompt_command() { local Mag='\[\e[1;95m\]' local Gra='\[\e[1;30m\]' - - # set xterm title - echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007" + # set xterm title + echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007" PS1='' - if [[ $container == 'lxc' ]];then + if [[ $container == 'lxc' ]]; then PS1+="${Gra}[LXC:${R}" local host=$container_hostname case ${host:0:4} in - 'beta') - PS1+="${Yel}";; - 'prod') - PS1+="${Red}";; - *) + 'beta') + PS1+="${Yel}" + ;; + 'prod') + PS1+="${Red}" + ;; + *) ;; esac PS1+="${host}${Gra}] " fi - - if [ `id -u` -eq 0 ]; then + + if [ $(id -u) -eq 0 ]; then PS1+="${Yel}\u${R}" PROMPT='$' else @@ -89,41 +89,44 @@ __prompt_command() { PS1+="${Gra}@" case ${HOSTNAME:0:4} in - 'beta') - PS1+="${Yel}";; - 'prod') - PS1+="${Red}";; - *) - PS1+="${R}";; + 'beta') + PS1+="${Yel}" + ;; + 'prod') + PS1+="${Red}" + ;; + *) + PS1+="${R}" + ;; esac PS1+="\h" - local pwd='~' - [ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/} + local pwd='~' + [ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/} PS1+=" ${Cya}${pwd}$(__vte_osc7)${R}" #PS1+=" ${Cya}\w${R}" if hash git 2>&-; then # git command exists - if git rev-parse --git-dir > /dev/null 2>&1; then + if git rev-parse --git-dir >/dev/null 2>&1; then # current dir is version controlled - local branch=$(git branch 2> /dev/null | grep -e ^* | cut -d ' ' -f2) + local branch=$(git branch 2>/dev/null | grep -e ^* | cut -d ' ' -f2) PS1+=" ${R}[${Mag}${branch}${R}|" - local tag_release=$(git describe --tags 2> /dev/null | cut -d'-' -f1) + local tag_release=$(git describe --tags 2>/dev/null | cut -d'-' -f1) local dirty=$(git status -s | wc -l) if [[ $dirty -ne 0 ]]; then PS1+="⚡|${tag_release}${Yel}…$dirty" else - local ahead=$(git rev-list --branches --not --remotes |wc -l) + local ahead=$(git rev-list --branches --not --remotes | wc -l) if [[ $ahead -ne 0 ]]; then PS1+="⚡|${tag_release}${Cya}↑${ahead}" else - if [[ -z $tag_release ]];then - PS1+="${Blu}✔" + if [[ -z $tag_release ]]; then + PS1+="${Blu}✔" else - PS1+="${Gre}✔${R}|${Blu}${tag_release}" + PS1+="${Gre}✔${R}|${Blu}${tag_release}" fi fi fi @@ -132,50 +135,46 @@ __prompt_command() { fi if [ $EXIT != 0 ]; then - PS1+="$Mag" # Add red if exit code non 0 + PS1+="$Mag" # Add red if exit code non 0 else PS1+="$Gra" fi PS1+=" $PROMPT ${R}" - -} +} -__vte_osc7 () { - # HINT: special character vte to get TILIX show proper hostname and pwd - # Use \[...\] around the parts of PS1 that have length 0. - # https://unix.stackexchange.com/questions/28827/why-is-my-bash-prompt-getting-bugged-when-i-browse-the-history#28828 - - VTE_INFO="${HOSTNAME:-}" - if [[ $container == 'lxc' ]];then - VTE_INFO="${container_hostname}" - fi - printf "\[\033]7;file://%s%s\a\]" "${VTE_INFO}" "$(__vte_urlencode "${PWD}")" +__vte_osc7() { + # HINT: special character vte to get TILIX show proper hostname and pwd + # Use \[...\] around the parts of PS1 that have length 0. + # https://unix.stackexchange.com/questions/28827/why-is-my-bash-prompt-getting-bugged-when-i-browse-the-history#28828 + VTE_INFO="${HOSTNAME:-}" + if [[ $container == 'lxc' ]]; then + VTE_INFO="${container_hostname}" + fi + printf "\[\033]7;file://%s%s\a\]" "${VTE_INFO}" "$(__vte_urlencode "${PWD}")" } - + __vte_urlencode() ( - # This is important to make sure string manipulation is handled - # byte-by-byte. - LC_ALL=C - str="$1" - while [ -n "$str" ]; do - safe="${str%%[!a-zA-Z0-9/:_\.\-\!\'\(\)~]*}" - printf "%s" "$safe" - str="${str#"$safe"}" - if [ -n "$str" ]; then - printf "%%%02X" "'$str" - str="${str#?}" - fi - done + # This is important to make sure string manipulation is handled + # byte-by-byte. + LC_ALL=C + str="$1" + while [ -n "$str" ]; do + safe="${str%%[!a-zA-Z0-9/:_\.\-\!\'\(\)~]*}" + printf "%s" "$safe" + str="${str#"$safe"}" + if [ -n "$str" ]; then + printf "%%%02X" "'$str" + str="${str#?}" + fi + done ) - PROMPT_COMMAND='__prompt_command' # Func to gen PS1 after CMDs - DEBIAN_BASH_DIR=/opt/debian-bash # You may uncomment the following lines if you want `ls' to be colorized: @@ -205,8 +204,13 @@ if [ -f ~/.bash_aliases ]; then fi # Add path to any tools folder in /opt/debian-* -for i in {/opt,$HOME}/debian-*/tools; do - if [ -d "$i" ]; then - PATH=$PATH:$i - fi +for i in {/opt,$HOME}/debian-*/tools; do + if [ -d "$i" ]; then + PATH=$PATH:$i + fi done + +## Add path for TOOLBOX if any +if [ -d "/TOOLBOX" ]; then + PATH=$PATH:/TOOLBOX +fi