Files
dotfiles/.termrc
2024-09-09 16:59:59 +02:00

168 lines
4.8 KiB
Plaintext

# Pre-define 'reload' in case .aliases dont provide it
alias reload='source ~/.termrc'
# Load personal aliases
source "$HOME/.aliases"
# Load tmux aliases if found
if [ -e $HOME/.tmux/.tmux-aliases ] ; then
source $HOME/.tmux/.tmux-aliases
fi
# Set base tmux session name
if [ -n "$WSLENV" ] ; then
HRNX_TMUX_SESSIONNAME="wsl"
else
HRNX_TMUX_SESSIONNAME="main"
fi
# Check if program is installed
function chkinst {
command -v $1 &>/dev/null
}
# Enable SSH keyring when kwallet is unavailable
if chkinst keychain && [ -n "$WSLENV"] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH2_CLIENT" ]; then
# Load SSH keychain
keychain -q --nogui ~/.ssh/id_rsa
source ~/.keychain/${HOST}-sh
#source ~/.keychain/${HOST}-sh-gpg
fi
# Add Rust crates to path
chkinst rust && export PATH=$PATH:$HOME/.cargo/bin
# Add snap bins to PATH (fuck snap)
chkinst snap && export PATH=$PATH:/snap/bin
# Add node global modules to PATH
if chkinst node && chkinst npm && nodepath=$(npm root -g); then
export PATH=$PATH:$nodepath
fi
# Usual env vars
export EDITOR=/usr/bin/vim
export LANG="en_US.UTF-8"
export LANGUAGE="en_US.UTF-8"
# Colors
alias diff='diff --color=auto'
alias grep='grep --color=auto'
alias ip='ip -color=auto'
alias ls='ls --color=auto'
# Decompress raw zlib files (.dat)
zlibd() (printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - "$@" | gzip -dc)
# Make scripts executable in a dir
fixsh () {
if [ -d $1 ] ; then
find $1 -type f -name "*.sh" -exec chmod a+x {} \;
find $1 -type f -name "*.bash" -exec chmod a+x {} \;
find $1 -type f -name "*.zsh" -exec chmod a+x {} \;
find $1 -type f -name "*.lua" -exec chmod a+x {} \;
find $1 -type f -name "*.py" -exec chmod a+x {} \;
find $1 -type f -name "*.pl" -exec chmod a+x {} \;
fi
}
# User scripts & bins executable
fixsh $HOME/sh
fixsh $HOME/bin
# Kilroy was here ! #2
export _KILROY_WAS_HERE=2
echo -e '\e[34m [termrc] Config reloaded\e[0m'
# Run WSL-specific inits
if [ -n "$WSLENV" ] ; then
printf '\e[34m [termrc] Running on WSL\e[0m\n'
# Enable entr workaround for incomplete inotify support on WSL
export ENTR_INOTIFY_WORKAROUND=1
# Add Ubuntu debuginfod server
export DEBUGINFOD_URLS="https://debuginfod.ubuntu.com"
# Re-init serial
reinit() (unset _SERIAL_INIT; reload)
# Connect serial console port if found
if [ -z "$_SERIAL_INIT" ] ; then
source "$HOME/.usbipd"
# Connect serial console ports
echo "Connecting serial port... (device ${USB_SERIAL_HWID:="0403:6001"})"
bus_ids=$( usbipd.exe list 2> /dev/null | grep "$USB_SERIAL_HWID" )
if [ -n "$bus_ids" ] ; then
echo $bus_ids
IFS=$' \t\n'
bus_ids=$( tr -s ' ' <<< $bus_ids | cut -d ' ' -f1 | tr '\n' ' ' )
for bus_id in $=bus_ids ; do
usbipd.exe attach --wsl --busid $bus_id 2> /dev/null
if [ $? -eq 0 ]; then
echo "Serial port $bus_id connected"
export _SERIAL_INIT=$(($_SERIAL_INIT+1))
else
echo "Unable to connect serial port (device $USB_SERIAL_HWID, bus $bus_id)"
fi
done
usbipd.exe wsl list 2> /dev/null
else
echo "No serial port found matching device type $USB_SERIAL_HWID"
export _SERIAL_INIT=0
fi
# Configure serial logs
if [ ! -d $SERIAL_LOGS ] ; then
if mkdir -p $SERIAL_LOGS; then echo "Serial logpath created at $SERIAL_LOGS"
else echo "Unable to create $SERIAL_LOGS"; fi
else
echo "Serial logs will be written to $SERIAL_LOGS"
fi
fi
# Automatically creates and attach a 'main' tmux session. If already created,
# attach in a new window instead. If running from tmux, does nothing.
if [ -z "$TMUX" ] && which tmux ; then
# Check if this script has already created a base session, then create a new session with a new blank window for the new terminal.
# If a session had already been created and left detached, attach to that instead.
if tmux has -t $HRNX_TMUX_SESSIONNAME ; then
if [ "$VSCODE_EMBEDDED_TERM" = 1 ] ; then
# Running from vscode terminal
count=$(tmux list-sessions -F "#S" -f "#{session_attached}" | grep vscode | wc -l)
tmux new-session -A -t $HRNX_TMUX_SESSIONNAME -s vscode-$(($count+1)) -e VSCODE_EMBEDDED_TERM=1 \; new-window -n vscode-$(($count+1))
else
# Running from another tab or window
count=$(tmux list-sessions -F "#S" -f "#{session_attached}" | grep $HRNX_TMUX_SESSIONNAME | wc -l)
tmux new-session -A -t $HRNX_TMUX_SESSIONNAME -s $HRNX_TMUX_SESSIONNAME-$(($count+1)) \; new-window
fi
else
# Create new base session
tmux new-session -A -s $HRNX_TMUX_SESSIONNAME -t $HRNX_TMUX_SESSIONNAME
fi
fi
# Env for 'mgnt toolbox' (rbsh, rbcli, etc)
export RBIP="10.102.88.203"
export RBLOG="administrator"
export RBPASS="administrator"
export RBROOTPASS="ekitool"
export PMCTL_SSH_IP="10.102.88.203"
export PMCTL_SSH_USER="root"
export PMCTL_SSH_PORT=2222
export _KILROY_WAS_HERE=3
# Setup functions for DEY SDK envs (pm800)
source ~/sh/sdk-setenv.sh
fi