diff --git a/.aliases b/.aliases index 0a06743..622cfe0 100644 --- a/.aliases +++ b/.aliases @@ -45,7 +45,24 @@ alias glgcm='git log --before=$(date -d"+ 1 month" "+%Y-%m-01") --after=$(date " alias glgt='git log --since="yesterday" --author="$(git config user.name)" --pretty=format:"%cd - %h - %s" \ --date=short --no-merges' alias reflog='git reflog --pretty=raw | tig --pretty=raw' -alias merged='git branch --merged master | grep -v master | xargs -n 1 git branch -d && git fetch --prune' +merged() { + local base_ref + + base_ref=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null || + { git show-ref --verify --quiet refs/remotes/origin/main && printf '%s\n' origin/main; } || + { git show-ref --verify --quiet refs/remotes/origin/master && printf '%s\n' origin/master; }) + + if [[ -z "$base_ref" ]]; then + echo "merged: unable to determine default branch (origin/HEAD not set)" >&2 + return 1 + fi + + git branch --merged "$base_ref" | + grep -vE '^\*|^[[:space:]]*(main|master)$' | + while read -r b; do git branch -d "$b"; done + + git fetch --prune +} alias gsw='git switch' alias gswc='git switch -c' alias grs='git restore' @@ -66,8 +83,8 @@ alias j='jobs -l' # grep alias grep='grep --color=auto' -alias egrep='egrep --color=auto' -alias fgrep='fgrep --color=auto' +alias egrep='grep -E --color=auto' +alias fgrep='grep -F --color=auto' # Quick HTTP server alias serve='ruby -run -e httpd . -p 8080' @@ -192,7 +209,6 @@ fi # kubectl if command -v kubectl &>/dev/null; then alias k=kubectl - complete -F __start_kubectl k alias netshoot='kubectl run netshoot-$(date +%s) --rm -i --tty --image nicolaka/netshoot -- /bin/bash' fi diff --git a/.config/bash/completions.bash b/.config/bash/completions.bash index ab2e593..4946241 100644 --- a/.config/bash/completions.bash +++ b/.config/bash/completions.bash @@ -27,3 +27,22 @@ if [[ -n "${HOMEBREW_PREFIX}" ]]; then unset _completion fi fi + +# gh CLI completions (includes gh copilot) +if command -v gh &>/dev/null && ! complete -p gh &>/dev/null; then + eval "$(gh completion -s bash)" +fi + +# kubectl completions (also covers the k alias defined in .aliases) +if command -v kubectl &>/dev/null; then + if ! declare -F __start_kubectl &>/dev/null; then + # shellcheck source=/dev/null + source <(kubectl completion bash) + fi + complete -o default -F __start_kubectl k +fi + +# terraform completions +if command -v terraform &>/dev/null; then + complete -C terraform terraform +fi diff --git a/.config/bash/options.bash b/.config/bash/options.bash index 9b61631..dd9ff3f 100644 --- a/.config/bash/options.bash +++ b/.config/bash/options.bash @@ -24,3 +24,18 @@ shopt -s extglob # case-insensitive glob matching shopt -s nocaseglob + +# enable ** recursive globbing (e.g. ls **/*.rb) +shopt -s globstar + +# update LINES/COLUMNS after each command (fixes resize artefacts) +shopt -s checkwinsize + +# cd by typing a path alone, without the cd command +shopt -s autocd + +# spell-correction for directory tab-completion +shopt -s dirspell + +# show history expansion result in readline buffer before executing +shopt -s histverify diff --git a/.inputrc b/.inputrc index 1e5a927..9599c8d 100644 --- a/.inputrc +++ b/.inputrc @@ -5,3 +5,11 @@ set show-all-if-ambiguous on set show-mode-in-prompt on set vi-cmd-mode-string \1\e[2 q\2 set vi-ins-mode-string \1\e[1 q\2 + +# Visual improvements +set colored-stats on +set colored-completion-prefix on +set mark-symlinked-directories on +set visible-stats on +set menu-complete-display-prefix on +set page-completions off diff --git a/.profile b/.profile index aec0f17..4a9bd43 100644 --- a/.profile +++ b/.profile @@ -33,7 +33,7 @@ fi export HISTFILE="${HOME}/.bash_history" export HISTSIZE=32768 export HISTFILESIZE=$HISTSIZE -export HISTCONTROL='ignoreboth' +export HISTCONTROL='ignoreboth:erasedups' export HISTIGNORE='ls:cd:cd -:pwd:exit:date:*--help:vault*:*VAULT_TOKEN*:*NOMAD_TOKEN*:*CONSUL_HTTP_TOKEN*' export HISTTIMEFORMAT='%h/%d -- %H:%M:%S ' @@ -57,7 +57,13 @@ fi export MANPATH="$HOME/.homebrew/share/man${MANPATH+:$MANPATH}:" # Don't clear the screen after quitting a manual page -export MANPAGER='less -X' +# Use bat for syntax-highlighted man pages when available, otherwise fall back +if command -v bat >/dev/null 2>&1; then + export MANPAGER="sh -c 'col -bx | bat -l man -p'" + export MANROFFOPT='-c' +else + export MANPAGER='less -X' +fi # color scheme # Keep the terminal's own TERM value (e.g. `xterm-ghostty`) when its terminfo @@ -96,7 +102,7 @@ export MYSQL_PS1='(\D) \u@\h [\d] > ' # 20ms for key sequences export KEYTIMEOUT=20 -# Setting ag as the default source for fzf +# Setting rg as the default source for fzf export FZF_DEFAULT_COMMAND='rg --files --ignore-vcs --hidden' # fzf preview