dotfiles/.bash_profile

87 lines
2.9 KiB
Bash

# Source bash specific set up,
[[ -f ~/.bashrc ]] && . ~/.bashrc
# Environment.
export EDITOR="nano"
export LANG="en_GB.UTF-8"
export LC_COLLATE="POSIX" # 'C' causes issues with some applications
# export LC_CTYPE="POSIX" # Not sure why I set this in the first place...
export LESS="-RM -j.5 -i -PM?f%F:stdin. -- Page %dt of %D -- %lt/%L (%Pt\%)$"
export PAGER="less"
export PATH="/opt/sbin:/usr/local/sbin:/usr/sbin:/sbin:$PATH"
export VISUAL="$EDITOR"
hash lesspipe >/dev/null 2>&1 && eval "$(SHELL=/bin/sh lesspipe)"
# Platform specific set up.
PLATFORM="$(uname -s)"
if [[ "$PLATFORM" = "Linux" ]]; then
export GPG_TTY="$(tty)" && gpg-connect-agent updatestartuptty /bye >/dev/null
export I_WANT_A_BROKEN_PS=1
export LYNX_CFG="$HOME/.lynx.cfg"
export LYNX_LSS="$HOME/.lynx.lss"
export MANPAGER="less"
export MANPATH="$HOME/.local/share/man:$MANPATH"
hash dircolors >/dev/null 2>&1 && eval "$(dircolors -b ~/.dir_colors)"
elif [[ "$PLATFORM" = "Darwin" ]]; then
export LSCOLORS="ExGxdxdxCxDxDxbcacbeae"
export MANPAGER="less -Mis -PM'Page %dt$'"
export MANPATH="/opt/local/share/man:$MANPATH"
export PATH="/opt/local/sbin:/opt/local/bin:$PATH"
else
echo "${BASH_SOURCE##*/}: unsupported platform: $PLATFORM" >&2
fi
unset PLATFORM
# Add bin directories to PATH.
[[ -d "$HOME/.local/bin" ]] && export PATH="$HOME/.local/bin:$PATH"
[[ -d "$HOME/bin" ]] && export PATH="$HOME/bin:$PATH"
[[ -d "$HOME/files/bin" ]] && export PATH="$HOME/files/bin:$PATH"
# Screen.
hash screen >/dev/null 2>&1 && {
[[ -e "$HOME/.screenrc-${HOSTNAME%%.*}" ]] && export SCREENRC="$HOME/.screenrc-${HOSTNAME%%.*}"
export SCREENDIR="$HOME/.screen-${HOSTNAME%%.*}"
if [[ -n "$SSH_TTY" ]]; then
if [[ -n "$STY" ]]; then
echo "Screen $STY, window $WINDOW."
echo
else
SCREENS="$(screen -ls | grep '[[:alpha:]]' | grep -E -v '^([[:digit:]]+|No) Socket(s)?')"
if [[ -n "$SCREENS" ]]; then
echo "$SCREENS"
echo
else
echo "No screens."
echo
fi
unset SCREENS
fi
elif [[ -n "$STY" ]]; then
echo "Screen $STY, window $WINDOW."
echo
else
TTY="$(tty | cut -d/ -f3-)"
SCREENS="$(screen -list | grep -F "${HOSTNAME%%.*}" | grep -F "${TTY//\//-}")"
case "$(echo ${SCREENS:--n} | wc -l)" in
0)
# No screens found - start a new instance, if on a tty.
[[ "$TTY" == *tty* ]] && screen
;;
1)
# Just one screen - reconnect if it's not dead.
if (( $(echo "$SCREENS" | grep "Dead" | wc -l) == 1 )); then
echo "Found dead screen for $TTY:"
echo "$SCREENS" | sed -e 's/^/ /g'
else
screen -dr "${TTY//\//-}.${HOSTNAME%%.*}"
fi
;;
*)
# Multiple screens - output a list
echo "Multiple screens found for $TTY:"
echo "$SCREENS" | sed -e 's/^/ /g'
;;
esac
unset SCREENS
fi
}