75 lines
2 KiB
Bash
75 lines
2 KiB
Bash
#!/usr/bin/env bash
|
|
# Custom bash settings
|
|
|
|
# get parent process name
|
|
local parent="$(ps -o command= -p "$PPID" | cut -f1 -d' ')"
|
|
if [[ "$parent" == *alacritty ]]; then
|
|
if [[ -z "$TMUX" && -z "$NOTMUX" ]]; then
|
|
if [[ "$PWD" == "$HOME" ]]; then
|
|
exec sh-tmux
|
|
else
|
|
exec sh-tmux -n
|
|
fi
|
|
fi
|
|
# set shell level
|
|
elif [[ "$parent" == "tmux" ]]; then
|
|
export SHLVL=2
|
|
fi
|
|
|
|
# default prompt command sets window title
|
|
unset PROMPT_COMMAND
|
|
# save command history to ~/.cache/bash_history, no limit
|
|
_load history
|
|
# aliases
|
|
_load aliases
|
|
# set xdg env vars to keep home directory clean
|
|
_load xdg
|
|
|
|
if _exists fzf; then
|
|
export FZF_DEFAULT_OPTS="--bind=ctrl-u:page-up,ctrl-d:page-down"
|
|
eval "$(fzf --bash)"
|
|
fi
|
|
_exists zoxide && eval "$(zoxide init bash)"
|
|
|
|
# use starship prompt, unless in linux terminal
|
|
if [[ "$TERM" != "linux" ]]; then
|
|
function _set_win_title {
|
|
# check if still in .bashrc
|
|
if declare -F _bashrc_main > /dev/null; then
|
|
return
|
|
elif [[ "$@" != @("starship_precmd"|""|"__fzf_history__"|"history -a"|"__zoxide_hook") ]]; then
|
|
printf "\e]0;%s | %s | %s\a" "$(dirs +0)" "$@" "$(date +"%H:%M:%S")"
|
|
fi
|
|
}
|
|
_exists starship && eval "$(starship init bash)"
|
|
# set window title after running command
|
|
trap "$(trap -p DEBUG | awk -F"'" '{print $2 ";"}')_set_win_title \"\${BASH_COMMAND}\"" DEBUG
|
|
else
|
|
# [username pwd] green $ reset
|
|
PS1="[\u \W] \[\e[32;1m\]\$\[\e[0m\] "
|
|
# set shell level
|
|
if [[ "$parent" == "login" ]]; then
|
|
export SHLVL=0
|
|
fi
|
|
fi
|
|
|
|
|
|
# set vi mode
|
|
set -o vi
|
|
_exists nvim && export EDITOR=nvim || export EDITOR=vim
|
|
export BROWSER=firefox
|
|
|
|
# disable xon/xoff flow control (ctrl-s, ctrl-q)
|
|
stty -ixon
|
|
# do not need to use cd to change directories
|
|
shopt -s autocd
|
|
# do not overwrite files when redirecting
|
|
set -o noclobber
|
|
# glob hidden files
|
|
shopt -s dotglob
|
|
|
|
# startup script for choosing environment
|
|
if [[ -z $DISPLAY && "$(tty)" == "/dev/tty1" ]]; then
|
|
_load startup
|
|
fi
|