Skip to content

Instantly share code, notes, and snippets.

@chanshing
Last active November 27, 2025 11:14
Show Gist options
  • Select an option

  • Save chanshing/c7c30e076eefc261de1405a40d2a60a7 to your computer and use it in GitHub Desktop.

Select an option

Save chanshing/c7c30e076eefc261de1405a40d2a60a7 to your computer and use it in GitHub Desktop.
Minimal .bashrc with color prompt, git prompt & git autocomplete
# git prompt & autocomplete
. ~/git-prompt.sh
. ~/git-completion.bash
export GIT_PS1_SHOWDIRTYSTATE=1
# prompt
MY_PROMPT='\u@\h' # user@host
PS1='\[\033[01;32m\]'"${MY_PROMPT}"'\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1 " (%s)")\$ '
# aliases - python
alias py='python'
alias ipy='ipython'
# aliases - tmux
alias ta='tmux attach -t'
alias tl='tmux ls'
alias tn='tmux new -s'
alias tk='tmux kill-session -t'
# aliases - git
alias gnp='git --no-pager'
# Add an "alert" alias for long running commands. Use like so: sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# glow -p
# NOTE: if using OMZ, uncomment next line:
# unalias md 2>/dev/null
md() {
local t="$1"
if [[ -z "$t" ]]; then
if [[ -n "$ZSH_VERSION" ]]; then
eval 't=(README.md README.MD Readme.md(N[1]))'
else
for f in README.md README.MD Readme.md; do
if [[ -f "$f" ]]; then
t="$f"
break
fi
done
fi
if [[ -z "$t" ]]; then
echo "Specify a .md file" >&2
return 1
fi
fi
glow -p -- "$t"
}
# press V for vi
set -o vi
export VISUAL=vi
# case-insensitive 'less' command
export LESS='-I'
# pretty print CSV files
csvless() {
column -t -s ',' -o ' | ' < "$1" | less -S
}
# Copy command that works everywhere
clip() {
if [[ -n "$TMUX" ]]; then
# Inside tmux
printf "\033]52;c;$(base64 | tr -d '\n')\007"
else
# Outside tmux
printf "\033]52;c;$(base64 | tr -d '\n')\007"
fi
}
# Usage: cat file.txt | clip
# or: echo "text" | clip
# Additional setup:
# iTerm2: General > Selection > Applications in terminal may access clipboard
# Windows Terminal: Should work out of the box
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment