dotfiles/dot_sshrc.tmpl
Stefan Gaiselmann 2728eb2c95 Secured .sshrc sourcing.
SOURCE_PROFILE and SOURCE_BASHRC are used to enable sourcing of .bashrc
and .profile.
This is due to an alternative way to source .sshrc from .bashrc, an
infinite loop must be avoided if using 's' alias with sourcing .sshrc.
2020-11-08 14:06:53 +01:00

117 lines
2.7 KiB
Cheetah

#
# sshrc will be called byaliased ssh command 's'.
#
if [ -f $HOME/.profile ] && [ "$SOURCE_PROFILE" = "true" ]; then
source $HOME/.profile
fi
if [ -f $HOME/.bashrc ] && [ "$SOURCE_BASHRC" = "true" ]; then
source $HOME/.bashrc
fi
#
# System Name and type detectedn
#
mySystem=$(uname -n)
myFQDN="$(uname -n).$(dnsdomainname)"
myCategory="{{.bash.prompt.category}}"
myType="{{.chezmoi.hostname}}"
myPrettyName="{{.chezmoi.osRelease.prettyName}}"
myNum=0
# last exit code
function lastExitCode {
local exit="$?"
if [ $exit != 0 ];then
printf '\e[38;5;160m%-5s' "✕ ❗ ($exit)"
else
printf '✔'
fi
}
# sourcing Solarized Theme
# and building PS1 prompt
source $HOME/.solarize_colors_base
echo "mySystem: $mySystem"
echo "myFQDN: $myFQDN"
bg_type="\[\e[48;5;254m\]"
bg_reset="\[\e[49m\]"
fg_reset="\[\e[39m\]"
bg_system="${sol_bg_magenta}"
fg_system="${sol_base3}"
fg_type="${sol_magenta}"
bg_type="${sol_bg_base3}"
fg_arrow1="${fg_type}"
fg_arrow2="${sol_base3}"
if [[ -z "${myType// }" ]]; then
TYPE=$(uname -n)
else
TYPE=" $myType "
fi
if [ "$myNum" != "0" ]; then
TYPE="$TYPE ($myNum)"
fi
echo "System Prompt: $SYSTEM_PROMPT"
SYSTEM_PROMPT="\n${fg_arrow1}░▒▓${bg_system} ${fg_system}${myCategory} ${bg_type}${fg_arrow1}▓▒░"
TYPE_PROMPT="$TYPE  \$(lastExitCode) ${fg_arrow1}$myPrettyName ${sol_blue}\${STY#[0-9]*.} ${bg_reset}${fg_arrow2}▓▒░"
PROMPT="${SYSTEM_PROMPT} ${TYPE_PROMPT}"
DATE="\[\e[0;32m\]\d \t"
if [ "$(whoami)" = "root" ]; then
DIR="\[\e[97;49m\]\[\e[0;91;107m\] \u@\h \[\e[97;49m\]\[\e[39;49m\] in \[\e[0;32m\]\w"
else
DIR="\[\e[0;32m\]\u@\h \[\e[31m\]☆ \[\e[0;32m\]\w"
fi
# PROMPT_COMMAND=promptcmd
PS1="${PROMPT}\[\e[0m\] \n${DIR}\n${DATE} → \[\e[0m\]"
if [ $(whoami | grep root | wc -l) == 1 ]; then
echo -e "\e[31;107m┌─────────────────────────────┐\e[0m"
echo -e "\e[31;107m│ YOU ARE ROOT, BE CAREFUL! │\e[0m"
echo -e "\e[31;107m└─────────────────────────────┘\e[0m"
# Test mintty
echo -ne '\e]11;44,10,10\a'
fi
# TODO: background colors...
# TODO: private history file for shared accounts
# TODO: vim
export LS_OPTIONS='--color=auto'
eval "$(dircolors -b)"
alias ls='ls $LS_OPTIONS'
alias psg='ps -aux | grep -v grep | grep '
# Some functions (some by c't magazine)
cdl() {
cd "$@"
if [ "$?" == 0 ]; then
ls
fi
}
backup() {
cp -p "$@" "$@".backup-$(date +%Y-%m-%d_%H_%M_%S)
}
extract() {
case $1 in
*.tar.bz2) tar xvjf $1;;
*.tar.gz|*.tgz) tar xvfz $1;;
*.zip) unzip $1;;
*) echo "Not supported: $1";;
esac
}
PATH=$PATH:$HOME/bin