From ad5d822f6fd5d0b5273ba18685b360deecb8e66a Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Sat, 28 Mar 2026 23:29:53 +0100 Subject: [PATCH] feat: bash --- bash/.bashrc | 15 +++++++++++++++ bash/.bashrc.d/aliases | 12 ++++++++++++ bash/.bashrc.d/autocomplete | 35 +++++++++++++++++++++++++++++++++++ bash/.bashrc.d/git | 20 ++++++++++++++++++++ bash/.bashrc.d/ps1 | 28 ++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 bash/.bashrc create mode 100644 bash/.bashrc.d/aliases create mode 100644 bash/.bashrc.d/autocomplete create mode 100644 bash/.bashrc.d/git create mode 100644 bash/.bashrc.d/ps1 diff --git a/bash/.bashrc b/bash/.bashrc new file mode 100644 index 0000000..88b1564 --- /dev/null +++ b/bash/.bashrc @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +PATH=$HOME/.local/share/bin/:$PATH + +function load() { + if [ -f "$1" ]; then + . "$1" + fi +} + +load $HOME/.bashrc.d/aliases +load $HOME/.bashrc.d/git +load $HOME/.bashrc.d/ps1 +load $HOME/.bashrc.d/autocomplete + +PROMPT_COMMAND=set_prompt diff --git a/bash/.bashrc.d/aliases b/bash/.bashrc.d/aliases new file mode 100644 index 0000000..54b28e7 --- /dev/null +++ b/bash/.bashrc.d/aliases @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +alias ls='ls --color=auto' +alias la='ls --color=auto -lah' + +if git --version | awk '{print $3}' | awk -F. '{ if (($1>2) || ($1==2 && $2>=12)) exit 0; else exit 1 }'; then + alias gcl='git clone --recurse-submodules -j$(($(nproc) / 2))' + else + alias gcl='git clone --recurse-submodules' +fi + +[ "$TERM" = "xterm-kitty" ] && alias ssh="kitty +kitten ssh" diff --git a/bash/.bashrc.d/autocomplete b/bash/.bashrc.d/autocomplete new file mode 100644 index 0000000..c2beb71 --- /dev/null +++ b/bash/.bashrc.d/autocomplete @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +function setup_completion() { + [[ $- == *i* ]] || return + + bind 'set colored-stats on' + bind 'set visible-stats on' + bind 'set mark-symlinked-directories on' + bind 'set colored-completion-prefix on' + bind 'set show-all-if-ambiguous on' + bind 'set completion-ignore-case on' + bind 'set page-completions off' + bind 'set menu-complete-display-prefix on' + bind 'set completion-query-items -1' + bind 'TAB:menu-complete' + bind '"\e[Z":menu-complete-backward' + export COMP_WORDBREAKS="${COMP_WORDBREAKS//\/}" + bind 'set mark-directories on' + bind 'set mark-symlinked-directories on' +} + +function setup_fzf() { + local fzf_dir + for fzf_dir in /usr/share/fzf /usr/share/doc/fzf/examples; do + if [ -d "$fzf_dir" ]; then + [ -f "$fzf_dir/key-bindings.bash" ] && . "$fzf_dir/key-bindings.bash" + [ -f "$fzf_dir/completion.bash" ] && . "$fzf_dir/completion.bash" + return + fi + done +} + +. /etc/bash_completion +setup_completion +setup_fzf diff --git a/bash/.bashrc.d/git b/bash/.bashrc.d/git new file mode 100644 index 0000000..70fff31 --- /dev/null +++ b/bash/.bashrc.d/git @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +COLOR_GIT_CLEAN='\001\033[38;5;107m\002' +COLOR_GIT_MODIFIED='\001\033[38;5;180m\002' +COLOR_GIT_STAGED='\001\033[38;5;223m\002' +COLOR_RESET='\001\033[0m\002' + +function git_prompt() { + if git rev-parse --is-inside-work-tree &>/dev/null; then + local branch_name + branch_name=$(git symbolic-ref --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null) + if git diff --quiet --ignore-submodules HEAD 2>/dev/null; then + echo -ne " ${COLOR_GIT_CLEAN}${branch_name}${COLOR_RESET}" + elif ! git diff --cached --quiet --ignore-submodules HEAD 2>/dev/null; then + echo -ne " ${COLOR_GIT_STAGED}${branch_name}${COLOR_RESET}" + else + echo -ne " ${COLOR_GIT_MODIFIED}${branch_name}*${COLOR_RESET}" + fi + fi +} diff --git a/bash/.bashrc.d/ps1 b/bash/.bashrc.d/ps1 new file mode 100644 index 0000000..56c5bf8 --- /dev/null +++ b/bash/.bashrc.d/ps1 @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +function git_prompt() { + local branch + branch=$(git symbolic-ref --short HEAD 2>/dev/null) || return + echo " (${branch})" +} + +function set_prompt() { + local exit_code=$? + + local reset="\001\033[0m\002" + local color_user="\001\033[38;5;109m\002" + local color_host="\001\033[38;5;144m\002" + local color_path="\001\033[38;5;246m\002" + local color_error="\001\033[31;49m\002" + + local prompt_symbol + if [[ $exit_code -ne 0 ]]; then + prompt_symbol="${color_error}\$${reset}" + else + prompt_symbol="\$" + fi + + PS1="${color_user}\u${reset}@${color_host}\h${reset} [ ${color_path}\w${reset}\$(git_prompt) ]${prompt_symbol} " +} + +PROMPT_COMMAND=set_prompt