150 lines
4.0 KiB
Bash
150 lines
4.0 KiB
Bash
# If not running interactively, don't do anything
|
|
[[ -z "$PS1" ]] && return
|
|
[[ $- == *i* ]] && stty -ixon
|
|
|
|
####
|
|
# settings
|
|
set -o vi
|
|
shopt -s checkwinsize # update the values of LINES and COLUMNS.
|
|
shopt -s nullglob
|
|
bind 'set enable-bracketed-paste off'
|
|
LANG="en_US.UTF-8"
|
|
LC_COLLATE="en_US.UTF-8"
|
|
LC_CTYPE="en_US.UTF-8"
|
|
LC_MESSAGES="en_US.UTF-8"
|
|
LC_MONETARY="en_US.UTF-8"
|
|
LC_NUMERIC="en_US.UTF-8"
|
|
LC_TIME="en_US.UTF-8"
|
|
LC_ALL=
|
|
GDK_BACKEND=wayland
|
|
|
|
####
|
|
# paths
|
|
function in_path() {
|
|
new_path="$1"
|
|
a=0
|
|
while true; do
|
|
a=$((a+1))
|
|
current="$(cut -d: -f"${a}" <<< "$PATH")"
|
|
if [[ -z "$current" ]]; then
|
|
return 1
|
|
fi
|
|
if [[ "$new_path" == "$current" ]]; then
|
|
return 0
|
|
fi
|
|
done
|
|
}
|
|
unset additional_paths
|
|
declare -a additional_paths
|
|
additional_paths=(
|
|
"${HOME}/bin"
|
|
"${HOME}/bin2"
|
|
"${HOME}/go/bin"
|
|
"${HOME}/local/bin"
|
|
"${HOME}/.cargo/bin"
|
|
"${HOME}/git/cr/depot_tools"
|
|
"/usr/local/go/bin/"
|
|
)
|
|
for path in "${additional_paths[@]}"; do
|
|
in_path "$path" || PATH="${path}:${PATH}"
|
|
done
|
|
unset additional_paths
|
|
unset in_path
|
|
|
|
####
|
|
# sources
|
|
unset sources
|
|
declare -a sources
|
|
sources=(
|
|
"${HOME}/.bash_aliases"
|
|
"${HOME}/.bash_functions"
|
|
"${HOME}/.bash_functions2"
|
|
"${HOME}/.cargo/env"
|
|
"${HOME}/.config/gom/init"
|
|
"${KITTY_INSTALLATION_DIR}/shell-integration/bash/kitty.bash"
|
|
)
|
|
|
|
for source in "${sources[@]}"; do
|
|
if [[ -r "${source}" ]]; then
|
|
. "${source}"
|
|
fi
|
|
done
|
|
unset sources
|
|
|
|
if [[ -d "${HOME}/.config/aliases" ]]; then
|
|
readarray -d '' bash_sources < <(find "${HOME}/.config/aliases" -type f | sort -V | tr '\n' '\0')
|
|
for source in "${bash_sources[@]}"; do
|
|
. "$source"
|
|
done
|
|
fi
|
|
|
|
####
|
|
# env
|
|
export HISTCONTROL=ignoredups
|
|
export HISTCONTROL=ignoreboth
|
|
export PS1='$ '
|
|
export VISUAL=vim
|
|
export EDITOR="$VISUAL"
|
|
export SYSTEMD_PAGER="cat"
|
|
export GIT_PAGER="cat"
|
|
export XDG_CONFIG_HOME="${HOME}/.config"
|
|
export XDG_CURRENT_DESKTOP=sway
|
|
export MOZ_ENABLE_WAYLAND=1
|
|
|
|
case "$TERM" in
|
|
screen-256color) export PS1='\[\033[1;35m\]\d \t ${debian_chroot:+($debian_chroot)}\[\033[0;55m\]\H\[\033[00m\]:\[\033[01;55m\]\w\[\033[00m\]\n\$ ' && alias ls='ls --color=auto';;
|
|
esac
|
|
|
|
##############################
|
|
# ssh auth sock
|
|
auth_sock_dir="${HOME}/.config/ssh"
|
|
auth_sock_log="/tmp/ssh_auth_sock"
|
|
if [[ ! -d "$auth_sock_dir" ]]; then
|
|
mkdir -p "$auth_sock_dir"
|
|
fi
|
|
ssh_auth_link="${auth_sock_dir}/ssh_auth_sock"
|
|
pgrep ssh-agent &>/dev/null
|
|
if [[ "$?" == "1" ]]; then
|
|
. <(ssh-agent | sed 's/echo/#echo/' | tee "$auth_sock_log")
|
|
if [[ -L "$ssh_auth_link" ]]; then
|
|
rm "$ssh_auth_link"
|
|
fi
|
|
if [[ -z "$SSH_AUTH_SOCK" ]]; then
|
|
printf 'Something went wrong with ssh-agent:\n' >&2
|
|
cat "$auth_sock_log" >&2
|
|
else
|
|
ln -s "$SSH_AUTH_SOCK" "$ssh_auth_link"
|
|
fi
|
|
fi
|
|
[[ -L "${ssh_auth_link}" ]] && [[ -e "${ssh_auth_link}" ]] && export SSH_AUTH_SOCK="$ssh_auth_link"
|
|
|
|
# autotmux
|
|
# export AT=true on connecting host to enable
|
|
default_session=shell
|
|
tls 2>/dev/null | grep -E "$default_session"'.*attached' &>/dev/null
|
|
not_in_tmux="$?"
|
|
no_auto="${HOME}/.config/autotmux/disable"
|
|
if [[ ! -f "$no_auto" ]] && [[ "$AT" == 'true' ]] && [[ "$not_in_tmux" ]]; then
|
|
stx "${default_session}"
|
|
fi
|
|
|
|
# Eternal bash history.
|
|
# ---------------------
|
|
# Undocumented feature which sets the size to "unlimited".
|
|
# http://stackoverflow.com/questions/9457233/unlimited-bash-history
|
|
export HISTFILESIZE=
|
|
export HISTSIZE=
|
|
export HISTCONTROL=ignoredups:erasedups
|
|
export HISTTIMEFORMAT="[%F %T] "
|
|
shopt -s histappend
|
|
|
|
# export HISTTIMEFORMAT="[%F %T] $(/home/luke/bin/history_status) "
|
|
# Change the file location because certain bash sessions truncate .bash_history file upon close.
|
|
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
|
|
export HISTFILE=~/.bash_eternal_history
|
|
# Force prompt to write history after every command.
|
|
# http://superuser.com/questions/20900/bash-history-loss
|
|
# PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
|
|
# PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
|
|
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
|