exec bash -l and exec bash both fixed
This commit is contained in:
+29
-83
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user