Browse Source

exec bash -l and exec bash both fixed

main
pvincent 5 days ago
parent
commit
6808c5d734
  1. 112
      etc/bash.bashrc
  2. 7
      etc/profile.d/20-miaou-bash.sh
  3. 4
      etc/profile.d/zz-miaou-bash.sh
  4. 2
      lib/initiate.bash
  5. 3
      lib/uninstall.bash

112
etc/bash.bashrc

@ -1,13 +1,14 @@
#!/bin/bash #!/bin/bash
# shellcheck disable=SC2139
function __prompt_command {
# TODO: needs some refactoring
function __miaou_prompt_command {
local EXIT="$?" # This needs to be first local EXIT="$?" # This needs to be first
local R='\[\e[0m\]' local R='\[\e[0m\]'
local Red='\[\e[31m\]' local Red='\[\e[31m\]'
local Gre='\[\e[32m\]' local Gre='\[\e[32m\]'
local Yel='\[\e[93m\]' local Yel='\[\e[93m\]'
local Blu='\[\e[34m\]'
local Cya='\[\e[36m\]' local Cya='\[\e[36m\]'
local Mag='\[\e[95m\]' local Mag='\[\e[95m\]'
local Gra='\[\e[90m\]' local Gra='\[\e[90m\]'
@ -25,23 +26,7 @@ function __prompt_command {
PS1='' PS1=''
IFS=' ' 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" PS1+="$Yel\u$R"
PROMPT='$' PROMPT='$'
else else
@ -49,24 +34,11 @@ function __prompt_command {
PROMPT='#' PROMPT='#'
fi 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='~' local pwd='~'
[ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/} [ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/}
PS1+=" ${Cya}${pwd}$(__vte_osc7)${R}"
PS1+=" ${Cya}${pwd}${R}"
if hash git 2>&-; then if hash git 2>&-; then
# git command exists # git command exists
@ -117,37 +89,6 @@ function __prompt_command {
IFS="$previous_IFS" 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 ### MAIN
###------ ###------
@ -156,7 +97,9 @@ function __vte_urlencode {
[[ $- != *i* ]] && return [[ $- != *i* ]] && return
if [[ ! -v MIAOU_BASH_DIR ]]; then 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 fi
HOSTNAME=$(hostname -f) HOSTNAME=$(hostname -f)
@ -164,11 +107,11 @@ HISTCONTROL=ignoreboth
HISTSIZE=10000 HISTSIZE=10000
HISTFILESIZE=20000 HISTFILESIZE=20000
export BLOCK_SIZE=si
# append to the history file, don't overwrite it # append to the history file, don't overwrite it
shopt -s histappend shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
# check the window size after each command and, if necessary, # check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS. # update the values of LINES and COLUMNS.
shopt -s checkwinsize shopt -s checkwinsize
@ -184,27 +127,29 @@ if [[ -t 0 ]]; then
stty kill undef # release CTRL+U for the Readline library => undo stty kill undef # release CTRL+U for the Readline library => undo
fi fi
PROMPT_COMMAND='__prompt_command' # Func to gen PS1 after CMDs
export COLOR_OPTIONS=' --color=auto'
export LESS="r" export LESS="r"
# make less more friendly for non text input files, see lesspipe(1) # make less more friendly for non text input files, see lesspipe(1)
if [[ -x /usr/bin/lesspipe ]]; then eval "$(SHELL=/bin/sh lesspipe)"; fi if [[ -x /usr/bin/lesspipe ]]; then eval "$(SHELL=/bin/sh lesspipe)"; fi
# ALIASES # 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 l=ls
alias sudo='sudo ' # the smart sudo alias trick!
alias cd..='cd ..' alias cd..='cd ..'
alias ..=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 transfer_cp='rsync -a --info=progress2 --no-inc-recursive'
alias ssu='ss -tupn'
alias ssu='ss -tlnp4'
# OVERRIDDEN ALIASES # OVERRIDDEN ALIASES
# shellcheck source=/dev/null # shellcheck source=/dev/null
[[ -f "/etc/bash.aliases" ]] && source "/etc/bash.aliases" [[ -f "/etc/bash.aliases" ]] && source "/etc/bash.aliases"
@ -218,8 +163,7 @@ function miaou-bash {
if [[ "$code" == 0 ]]; then if [[ "$code" == 0 ]]; then
if [[ "${1:-}" =~ --self-upgrade|--uninstall ]]; then if [[ "${1:-}" =~ --self-upgrade|--uninstall ]]; then
echo 'reloading session now!' echo 'reloading session now!'
#exec bash -l
exec bash
exec bash -l
fi fi
fi fi
return $code return $code
@ -237,4 +181,6 @@ fi
## Add path for TOOLBOX if any ## Add path for TOOLBOX if any
[[ -d "/TOOLBOX" ]] && PATH=$PATH:/TOOLBOX || true [[ -d "/TOOLBOX" ]] && PATH=$PATH:/TOOLBOX || true
# Add path to any tools folder in /opt/miaou-* # 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

7
etc/profile.d/20-miaou-bash.sh

@ -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

4
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

2
lib/initiate.bash

@ -125,7 +125,7 @@ function link_config_files {
else else
link_etc vim/vimrc.local link_etc vim/vimrc.local
fi fi
link_etc profile.d/20-miaou-bash.sh
link_etc profile.d/zz-miaou-bash.sh
link_etc bash.bashrc link_etc bash.bashrc
link_etc bash_completion.d/miaou-bash.complete link_etc bash_completion.d/miaou-bash.complete
link_etc inputrc # last command required to detect successful installation link_etc inputrc # last command required to detect successful installation

3
lib/uninstall.bash

@ -19,7 +19,8 @@ function uninstall {
restore /etc/inputrc restore /etc/inputrc
restore /etc/skel/.bashrc 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 /etc/vimrc/vimrc.{azerty,core,local,miaou,rookie}
sudo rm -f /usr/bin/miaou-bash sudo rm -f /usr/bin/miaou-bash
sudo rm -f /etc/sudoers.d/miaou-bash sudo rm -f /etc/sudoers.d/miaou-bash

Loading…
Cancel
Save