Skip to content

Instantly share code, notes, and snippets.

@smuuf
Last active May 15, 2023 21:57
Show Gist options
  • Save smuuf/61443e4e70805cf6a8324a6b371545c4 to your computer and use it in GitHub Desktop.
Save smuuf/61443e4e70805cf6a8324a6b371545c4 to your computer and use it in GitHub Desktop.
Pretty prompt alá smuuf
# smuuf.bashrc
# Prompt formatting
# 10:20:49 /etc
# [smuuf@smuuf-xubuntu]$
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
}
NC="$(tput sgr0)"
export PS1="\e[90m\$(parse_git_branch)"
export PS1=$PS1"\[\e[38;5;7m\]\t\[$NC\]\[\e[38;5;15m\] \[$NC\]\[\e[38;5;30m\]\w\[$NC\]\[\e[38;5;15m\]\n\[$NC\]\[\e[38;5;7m\][\[$NC\]\[\e[38;5;202m\]\u\[$NC\]\[\e[38;5;15m\]@\[$NC\]\[\e[38;5;33m\]\h\[$NC\]\[\e[38;5;7m\]]\[$NC\]\[\e[38;5;15m\]\\$ \[$NC\]"
# Differentiate WSL version
VERSION=`cat /proc/version`
if [[ "$VERSION" =~ "[email protected]" ]]; then
echo "Running WSL 1"
WSL_1=1
elif [[ "$VERSION" =~ "microsoft-standard" ]]; then
echo "Running WSL 2"
WSL_2=1
fi
# XServer display for WSL
export LIBGL_ALWAYS_INDIRECT=1
if [[ "$WSL_1" ]]; then
export DISPLAY=:0 # in WSL 1
fi
if [[ "$WSL_2" ]]; then
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0 # in WSL 2
fi
# WAV to MP3 converting via ffmpeg.
function wavtomp3 {
ffmpeg -i "$1" -vn -ar 44100 -ac 2 -b:a 320k "${1/.wav/.mp3}"
}
# Other useful aliases.
alias snano="sudo nano"
alias gpull="git pull"
alias gpush="git push"
function cdenv {
cd $1
if [[ -f "./.venv" ]]; then
VENV=$(<.venv)
elif [[ -f "./env" ]]; then
VENV=$(<.venv)
fi
source ~/envs/$VENV/bin/activate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment