diff --git a/etc/bash.bashrc b/etc/bash.bashrc index 849ce2d..61148fa 100644 --- a/etc/bash.bashrc +++ b/etc/bash.bashrc @@ -1,13 +1,14 @@ #!/bin/bash +# shellcheck disable=SC2139 -function __prompt_command { +# TODO: needs some refactoring +function __miaou_prompt_command { local EXIT="$?" # This needs to be first local R='\[\e[0m\]' local Red='\[\e[31m\]' local Gre='\[\e[32m\]' local Yel='\[\e[93m\]' - local Blu='\[\e[34m\]' local Cya='\[\e[36m\]' local Mag='\[\e[95m\]' local Gra='\[\e[90m\]' @@ -25,23 +26,7 @@ function __prompt_command { PS1='' IFS=' ' - if [[ -n ${container_hostname:-} ]]; then - PS1+="${Gra}[LXC:${R}" - local host - host=$(builtin echo $container_hostname | tr ' ' ':') - case ${host:0:4} in - 'beta') - PS1+="${Yel}" - ;; - 'prod') - PS1+="${Red}" - ;; - *) ;; - esac - PS1+="${host}${Gra}] " - fi - - if [[ "$(id -u)" -eq 0 ]]; then + if [[ "$UID" -eq 0 ]]; then PS1+="$Yel\u$R" PROMPT='$' else @@ -49,24 +34,11 @@ function __prompt_command { PROMPT='#' fi - PS1+="${Gra}@" - - case ${HOSTNAME:0:4} in - 'beta') - PS1+="${Yel}" - ;; - 'prod') - PS1+="${Red}" - ;; - *) - PS1+="${R}" - ;; - esac - PS1+="$HOSTNAME" + PS1+="${Gra}@${R}${HOSTNAME}" local pwd='~' [ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/} - PS1+=" ${Cya}${pwd}$(__vte_osc7)${R}" + PS1+=" ${Cya}${pwd}${R}" if hash git 2>&-; then # git command exists @@ -117,37 +89,6 @@ function __prompt_command { IFS="$previous_IFS" } -function __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 [[ -n ${container_hostname:-} ]]; then - local host - host=$(builtin echo "$container_hostname" | tr ' ' ':') - VTE_INFO="$host:$HOSTNAME" - fi - printf "\[\033]7;file://%s%s\a\]" "${VTE_INFO}" "$(__vte_urlencode "${PWD}")" - -} - -function __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 -} - ###------ ### MAIN ###------ @@ -156,7 +97,9 @@ function __vte_urlencode { [[ $- != *i* ]] && return if [[ ! -v MIAOU_BASH_DIR ]]; then - source /etc/profile.d/20-miaou-bash.sh + source /etc/profile.d/zz-miaou-bash.sh +else + PROMPT_COMMAND=__miaou_prompt_command fi HOSTNAME=$(hostname -f) @@ -164,11 +107,11 @@ HISTCONTROL=ignoreboth HISTSIZE=10000 HISTFILESIZE=20000 +export BLOCK_SIZE=si + # append to the history file, don't overwrite it shopt -s histappend -# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) - # check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize @@ -184,27 +127,29 @@ if [[ -t 0 ]]; then stty kill undef # release CTRL+U for the Readline library => undo fi -PROMPT_COMMAND='__prompt_command' # Func to gen PS1 after CMDs - -export COLOR_OPTIONS=' --color=auto' export LESS="r" # make less more friendly for non text input files, see lesspipe(1) if [[ -x /usr/bin/lesspipe ]]; then eval "$(SHELL=/bin/sh lesspipe)"; fi # ALIASES -alias sudo='sudo ' # smart sudo alias trick! -alias ls='ls $COLOR_OPTIONS -h' -alias ll='ls $COLOR_OPTIONS -lh' -alias la='ls $COLOR_OPTIONS -lah' -alias ltr='ls $COLOR_OPTIONS -ltrh' + +COLOR_OPTIONS=('--color=auto') +alias ls="ls ${COLOR_OPTIONS[*]}" +alias ll="ls ${COLOR_OPTIONS[*]} -l" +alias la="ls ${COLOR_OPTIONS[*]} -la" +alias ltr="ls ${COLOR_OPTIONS[*]} -ltr" +alias grep="grep ${COLOR_OPTIONS[*]}" +alias fgrep="fgrep ${COLOR_OPTIONS[*]}" +alias egrep="egrep ${COLOR_OPTIONS[*]}" +unset COLOR_OPTIONS + alias l=ls +alias sudo='sudo ' # the smart sudo alias trick! alias cd..='cd ..' alias ..=cd.. -alias grep='grep $COLOR_OPTIONS ' -alias fgrep='fgrep $COLOR_OPTIONS ' -alias egrep='egrep $COLOR_OPTIONS ' alias transfer_cp='rsync -a --info=progress2 --no-inc-recursive' -alias ssu='ss -tupn' +alias ssu='ss -tlnp4' + # OVERRIDDEN ALIASES # shellcheck source=/dev/null [[ -f "/etc/bash.aliases" ]] && source "/etc/bash.aliases" @@ -218,8 +163,7 @@ function miaou-bash { if [[ "$code" == 0 ]]; then if [[ "${1:-}" =~ --self-upgrade|--uninstall ]]; then echo 'reloading session now!' - #exec bash -l - exec bash + exec bash -l fi fi return $code @@ -237,4 +181,6 @@ fi ## Add path for TOOLBOX if any [[ -d "/TOOLBOX" ]] && PATH=$PATH:/TOOLBOX || true # Add path to any tools folder in /opt/miaou-* -for i in {/opt,$HOME}/miaou-*/tools; do [[ -d "$i" ]] && PATH=$PATH:$i; done || true +for i in {/opt,$HOME}/miaou-*/tools; do + [[ -d "$i" ]] && PATH=$PATH:$i +done || true diff --git a/etc/profile.d/20-miaou-bash.sh b/etc/profile.d/20-miaou-bash.sh deleted file mode 100644 index 56ee386..0000000 --- a/etc/profile.d/20-miaou-bash.sh +++ /dev/null @@ -1,7 +0,0 @@ -MIAOU_BASH_DIR=/opt/miaou-bash -export MIAOU_BASH_DIR - -# useful when MIAOU_BASH_MODE=hosted/containerized -if [[ -f /var/lib/miaou-bash/semver_current ]]; then - "$MIAOU_BASH_DIR"/bin/miaou-bash "$MIAOU_BASH_DIR"/lib/container-upgrade.bash -fi diff --git a/etc/profile.d/zz-miaou-bash.sh b/etc/profile.d/zz-miaou-bash.sh new file mode 100644 index 0000000..f4fa742 --- /dev/null +++ b/etc/profile.d/zz-miaou-bash.sh @@ -0,0 +1,4 @@ +PROMPT_COMMAND=__miaou_prompt_command +MIAOU_BASH_DIR=/opt/miaou-bash + +export MIAOU_BASH_DIR diff --git a/lib/initiate.bash b/lib/initiate.bash index 66464e5..f956354 100644 --- a/lib/initiate.bash +++ b/lib/initiate.bash @@ -125,7 +125,7 @@ function link_config_files { else link_etc vim/vimrc.local fi - link_etc profile.d/20-miaou-bash.sh + link_etc profile.d/zz-miaou-bash.sh link_etc bash.bashrc link_etc bash_completion.d/miaou-bash.complete link_etc inputrc # last command required to detect successful installation diff --git a/lib/uninstall.bash b/lib/uninstall.bash index be533b6..624999f 100644 --- a/lib/uninstall.bash +++ b/lib/uninstall.bash @@ -19,7 +19,8 @@ function uninstall { restore /etc/inputrc restore /etc/skel/.bashrc - sudo rm /etc/profile.d/20-miaou-bash.sh + sudo rm -f /etc/profile.d/20-miaou-bash.sh # deprecated: for older version + sudo rm -f /etc/profile.d/zz-miaou-bash.sh sudo rm -f /etc/vimrc/vimrc.{azerty,core,local,miaou,rookie} sudo rm -f /usr/bin/miaou-bash sudo rm -f /etc/sudoers.d/miaou-bash