feat: bash
This commit is contained in:
commit
ad5d822f6f
5 changed files with 110 additions and 0 deletions
15
bash/.bashrc
Normal file
15
bash/.bashrc
Normal file
|
|
@ -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
|
||||||
12
bash/.bashrc.d/aliases
Normal file
12
bash/.bashrc.d/aliases
Normal file
|
|
@ -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"
|
||||||
35
bash/.bashrc.d/autocomplete
Normal file
35
bash/.bashrc.d/autocomplete
Normal file
|
|
@ -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
|
||||||
20
bash/.bashrc.d/git
Normal file
20
bash/.bashrc.d/git
Normal file
|
|
@ -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
|
||||||
|
}
|
||||||
28
bash/.bashrc.d/ps1
Normal file
28
bash/.bashrc.d/ps1
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Reference in a new issue