mirror of
https://github.com/itme-brain/bash.git
synced 2026-03-23 17:59:44 -04:00
initial bash config
This commit is contained in:
commit
25d055514d
3 changed files with 165 additions and 0 deletions
15
aliases
Normal file
15
aliases
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
# Navigation
|
||||||
|
alias cd='cd -L'
|
||||||
|
|
||||||
|
# Search
|
||||||
|
alias grep='grep --color'
|
||||||
|
|
||||||
|
# Tree (uses eza if available)
|
||||||
|
if command -v eza &>/dev/null; then
|
||||||
|
alias tree='eza --tree --icons=never'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Open (graphical environment only)
|
||||||
|
if [ -n "$DISPLAY" ] || [ -n "$WAYLAND_DISPLAY" ]; then
|
||||||
|
alias open='xdg-open'
|
||||||
|
fi
|
||||||
11
bashrc
Normal file
11
bashrc
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Source prompt and aliases
|
||||||
|
BASH_CONFIG_DIR="${BASH_SOURCE%/*}"
|
||||||
|
source "$BASH_CONFIG_DIR/prompt"
|
||||||
|
source "$BASH_CONFIG_DIR/aliases"
|
||||||
|
|
||||||
|
# Vi mode
|
||||||
|
set -o vi
|
||||||
|
|
||||||
|
# Completion
|
||||||
|
bind 'set completion-ignore-case on'
|
||||||
|
bind 'set completion-map-case on'
|
||||||
139
prompt
Normal file
139
prompt
Normal file
|
|
@ -0,0 +1,139 @@
|
||||||
|
# Detect graphical environment for icons
|
||||||
|
_has_graphics() {
|
||||||
|
[ -n "$DISPLAY" ] || [ -n "$WAYLAND_DISPLAY" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
check_ssh() {
|
||||||
|
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||||
|
ssh_PS1="\n\[\033[01;37m\]\u@\h:\[\033[00m\]\n"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Git-related functions (only if git available)
|
||||||
|
if command -v git &>/dev/null; then
|
||||||
|
|
||||||
|
check_venv() {
|
||||||
|
add_icon() {
|
||||||
|
local icon=$1
|
||||||
|
if [[ ! $venv_icons =~ $icon ]]; then
|
||||||
|
venv_icons+="$icon "
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_icon() {
|
||||||
|
local icon=$1
|
||||||
|
venv_icons=${venv_icons//$icon/}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _has_graphics; then
|
||||||
|
py=""
|
||||||
|
js=""
|
||||||
|
nix=""
|
||||||
|
else
|
||||||
|
py="py"
|
||||||
|
js="js"
|
||||||
|
nix="nix"
|
||||||
|
fi
|
||||||
|
|
||||||
|
python_icon="\[\033[01;33m\]$py\[\033[00m\]"
|
||||||
|
node_icon="\[\033[01;93m\]$js\[\033[00m\]"
|
||||||
|
nix_icon="\[\033[01;34m\]$nix\[\033[00m\]"
|
||||||
|
|
||||||
|
if [ -n "$IN_NIX_SHELL" ]; then
|
||||||
|
add_icon "$nix_icon"
|
||||||
|
else
|
||||||
|
remove_icon "$nix_icon"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$VIRTUAL_ENV" ]; then
|
||||||
|
add_icon "$python_icon"
|
||||||
|
else
|
||||||
|
remove_icon "$python_icon"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "${git_root}/node_modules" ]; then
|
||||||
|
add_icon "$node_icon"
|
||||||
|
else
|
||||||
|
remove_icon "$node_icon"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
set_git_dir() {
|
||||||
|
if _has_graphics; then
|
||||||
|
project_icon=" "
|
||||||
|
else
|
||||||
|
project_icon="../"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local superproject_root=$(git rev-parse --show-superproject-working-tree 2>/dev/null)
|
||||||
|
if [[ -n "$superproject_root" ]]; then
|
||||||
|
local submodule_name=$(basename "$git_root")
|
||||||
|
working_dir="\[\033[01;34m\]$project_icon${superproject_root##*/}/$submodule_name$git_curr_dir\[\033[00m\]"
|
||||||
|
elif [ "$git_curr_dir" == "." ]; then
|
||||||
|
working_dir="\[\033[01;34m\]$project_icon$git_root_dir\[\033[00m\]"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
working_dir="\[\033[01;34m\]$project_icon$git_root_dir$git_curr_dir\[\033[00m\]"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
relative_path() {
|
||||||
|
local absolute_target=$(readlink -f "$1")
|
||||||
|
local absolute_base=$(readlink -f "$2")
|
||||||
|
echo "${absolute_target#$absolute_base}"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_project() {
|
||||||
|
git_root=$(git rev-parse --show-toplevel 2>/dev/null)
|
||||||
|
|
||||||
|
if [ -n "$git_root" ]; then
|
||||||
|
git_branch=$(git branch --show-current 2>/dev/null)
|
||||||
|
|
||||||
|
if [ -z "$git_branch" ]; then
|
||||||
|
git_branch=$(git describe --tags --exact-match 2>/dev/null)
|
||||||
|
git_branch=${git_branch:-$(git rev-parse --short HEAD 2>/dev/null)}
|
||||||
|
fi
|
||||||
|
|
||||||
|
git_curr_dir=$(relative_path "." "$git_root")
|
||||||
|
git_root_dir=$(basename "$git_root")
|
||||||
|
|
||||||
|
if _has_graphics; then
|
||||||
|
git_branch_PS1="\[\033[01;31m\]$git_branch :\[\033[00m\]"
|
||||||
|
else
|
||||||
|
git_branch_PS1="\[\033[01;31m\]$git_branch:\[\033[00m\]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
set_git_dir
|
||||||
|
check_venv
|
||||||
|
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
fi # end git check
|
||||||
|
|
||||||
|
set_prompt() {
|
||||||
|
local green_arrow="\[\033[01;32m\]>> "
|
||||||
|
local white_text="\[\033[00m\]"
|
||||||
|
local working_dir="\[\033[01;34m\]\w\[\033[00m\]"
|
||||||
|
|
||||||
|
local ssh_PS1
|
||||||
|
|
||||||
|
check_ssh
|
||||||
|
|
||||||
|
if command -v git &>/dev/null; then
|
||||||
|
local venv_icons
|
||||||
|
local git_branch_PS1
|
||||||
|
|
||||||
|
check_project
|
||||||
|
|
||||||
|
PS1="$ssh_PS1\n$working_dir\n$venv_icons$green_arrow$git_branch_PS1$white_text"
|
||||||
|
else
|
||||||
|
PS1="$ssh_PS1\n$working_dir\n$green_arrow$white_text"
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
PROMPT_COMMAND="set_prompt"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue