Files
dotfiles/dot_bashrc.tmpl
T

228 lines
5.9 KiB
Cheetah
Raw Normal View History

2021-04-07 15:43:01 +02:00
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
[[ "$(whoami)" = "root" ]] && return
[[ -z "$FUNCNEST" ]] && export FUNCNEST=100 # limits recursive functions, see 'man bash'
2022-11-03 19:19:46 +01:00
# disable history
HISTFILE=/dev/null
2021-04-07 15:43:01 +02:00
## Use the up and down arrow keys for finding a command in history
## (you can write some initial letters of the command first).
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
2021-04-14 15:12:17 +02:00
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
2022-04-03 18:50:37 +02:00
# add home bin
if [ -d "$HOME/.local/bin" ]; then
export PATH="$HOME/.local/bin:$PATH"
fi
2021-04-07 15:43:01 +02:00
# ---------------------------------------------------------------------------
# EDITOR
# ---------------------------------------------------------------------------
2021-12-21 09:04:33 +01:00
if hash nvim 2>/dev/null; then
export EDITOR=nvim
elif hash vim 2>/dev/null; then
export EDITOR=vim
elif hash vi 2>/dev/null; then
export EDITOR=vi
else
export EDITOR=nano
2021-04-18 11:39:35 +02:00
fi
2021-04-07 15:43:01 +02:00
2021-12-21 09:04:33 +01:00
export SVN_EDITOR=$EDITOR
export GIT_EDITOR=$EDITOR
export VISUAL=$EDITOR
alias vi=$EDITOR
2021-04-07 15:43:01 +02:00
# ---------------------------------------------------------------------------
# ALIASES
# ---------------------------------------------------------------------------
2024-09-15 15:22:44 +02:00
if hash lsd 2>/dev/null; then
alias ls="lsd"
alias ll="ls -l"
alias la="ls -la"
elif hash exa 2>/dev/null; then
2021-12-21 09:04:33 +01:00
alias ll="exa --long --group-directories-first --classify --git"
alias la="ll --all"
else
alias ll="ls -lv --group-directories-first --ignore=.." # show long listing but no hidden dotfiles except "."
alias la='ls -lav'
2024-09-15 15:22:44 +02:00
test -r "~/.dir_colors" && eval $(dircolors ~/.dir_colors)
2021-12-21 09:04:33 +01:00
fi
2021-04-07 15:46:17 +02:00
alias rm='rm --interactive --verbose'
alias mv='mv --interactive --verbose'
alias cp='cp --verbose --interactive'
2022-11-06 12:25:28 +01:00
if hash wget 2>/dev/null; then
alias wget='wget -c'
fi
2021-04-07 15:46:17 +02:00
alias dmesg='dmesg -T'
alias grep='grep --color'
2021-04-07 15:43:01 +02:00
2022-11-06 12:25:28 +01:00
if hash tmux 2>/dev/null; then
alias ta='tmux attach'
alias tkill="for s in \$(tmux list-sessions | awk -F ':' '{print \$1}' | fzf); do tmux kill-session -t \$s; done;"
fi
2021-06-10 08:31:20 +02:00
2022-11-06 12:25:28 +01:00
if hash tig 2>/dev/null; then
alias tiga='tig --all'
fi
2021-06-28 11:14:39 +02:00
2021-12-30 07:23:00 +01:00
if hash fd 2>/dev/null; then
alias fdfind='fd'
fi
2022-11-06 12:25:28 +01:00
if hash nix-env 2>/dev/null; then
alias nix-update='nix-channel --update && nix-env -u'
2022-12-14 08:29:54 +01:00
nix-search() {
nix-env -qa --description ".*$1.*"
}
2022-11-06 12:25:28 +01:00
fi
2022-11-07 13:31:30 +01:00
alias cdd='cd {{ .deploydir }}'
2022-11-07 19:50:17 +01:00
export cdd={{ .deploydir }}
2022-11-07 13:31:30 +01:00
2024-09-05 16:49:58 +02:00
# ---------------------------------------------------------------------------
# TMUX
# ---------------------------------------------------------------------------
# Function to set tmux window title
function set_tmux_title {
if [ -n "$TMUX" ]; then
tmux rename-window "$1"
fi
}
# SSH wrapper to change the tmux title locally
function ssh() {
if [ -n "$TMUX" ]; then
# Save the original tmux window title
original_title=$(tmux display-message -p '#W')
fi
# Change tmux title before connecting
2024-09-11 14:39:24 +02:00
set_tmux_title "SSH $1"
2024-09-05 16:49:58 +02:00
# Run the actual ssh command with all arguments
command ssh "$@"
# Restore the original tmux window title after disconnecting
if [ -n "$TMUX" ]; then
set_tmux_title "$original_title"
tmux set-window-option automatic-rename on
2024-09-05 16:49:58 +02:00
fi
2022-11-15 08:48:23 +01:00
}
2024-09-11 14:39:24 +02:00
export FAVORITE_COMMAND1="{{ .tmux_favorite1 }}"
export FAVORITE_COMMAND2="{{ .tmux_favorite2 }}"
export FAVORITE_COMMAND3="{{ .tmux_favorite3 }}"
export FAVORITE_COMMAND4="{{ .tmux_favorite4 }}"
2022-04-05 08:26:49 +02:00
# ---------------------------------------------------------------------------
# COMPLETIONS
# ---------------------------------------------------------------------------
complete -W "\`grep -oE '^[a-zA-Z0-9_.-]+:([^=]|$)' ?akefile | sed 's/[^a-zA-Z0-9_.-]*$//'\`" make
2021-04-14 15:12:17 +02:00
# -------------------------------------------------------------
2021-11-22 14:44:26 +01:00
# Source .bashrc.d files
2021-04-14 15:12:17 +02:00
# -------------------------------------------------------------
2021-04-19 18:36:36 +02:00
if [ -d "$HOME/.bashrc.d/" ]; then
2021-04-17 19:05:21 +02:00
for file in ~/.bashrc.d/*.bashrc; do
. "$file"
done
fi
2021-04-14 15:12:17 +02:00
2024-08-29 11:03:27 +02:00
if [ -f "$HOME/.bashrc.local" ]; then
source $HOME/.bashrc.local
fi
2022-11-03 15:20:17 +01:00
# ---------------------------------------------------------------------------
# History
# ---------------------------------------------------------------------------
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# store multiline commands
shopt -s cmdhist
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=2000
HISTFILESIZE=2000
2022-08-11 11:52:09 +02:00
2022-11-03 15:20:17 +01:00
# don't story history commands
HISTIGNORE=history*
2022-09-06 16:53:19 +02:00
2022-11-03 19:19:46 +01:00
HISTFILE=~/.bash_history
2022-11-05 14:10:34 +01:00
# Hishtory (https://github.com/ddworken/hishtory)
if [ -d "$HOME/.hishtory/" ]; then
export PATH="$PATH:$HOME/.hishtory"
source $HOME/.hishtory/config.sh
2022-11-09 18:56:08 +01:00
hishtory config-set displayed-columns CWD Command
2022-11-05 14:10:34 +01:00
fi
2024-09-04 06:01:24 +02:00
# ---------------------------------------------------------------------------
# PROMPT
# ---------------------------------------------------------------------------
# starship must be evaluated at the end to catch properly error codes
if hash starship 2>/dev/null; then
eval "$(starship init bash)"
else
# set a minimalist prompt
red='\[\e[0;31m\]' # Red
green='\[\e[0;32m\]' # Green
blue='\[\e[0;34m\]' # Bold Blue
boldred='\[\e[1;31m\]' # Bold Red
reset='\[\e[0m\]' # Text Reset
if [ "$USER" = "root" ] ; then
# $bold$red
PROMPT_USER_COLOR=$boldred
PROMPT_SYMBOL="#"
else
PROMPT_USER_COLOR=$green
PROMPT_SYMBOL="$"
fi
if [[ -n "$SSH_CLIENT$SSH2_CLIENT$SSH_TTY" ]] ; then
PROMPT_SSH="@\h"
else
PROMPT_SSH=""
fi
PS1="$PROMPT_USER_COLOR\u$PROMPT_SSH $blue\w$reset $PROMPT_SYMBOL "
if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then
GIT_PROMPT_ONLY_IN_REPO=1
GIT_PROMPT_IGNORE_SUBMODULES=1
GIT_PROMPT_WITH_VIRTUAL_ENV=0
GIT_PROMPT_THEME=Solarized_Yax
source $HOME/.bash-git-prompt/gitprompt.sh
fi
2024-09-14 13:30:34 +02:00
fi
2024-09-20 11:31:54 +02:00
# enable history
set -o history