Skip to content

Instantly share code, notes, and snippets.

@disouzam
Last active October 25, 2024 00:47
Show Gist options
  • Save disouzam/199e15f8b94f10c69c46cade8c9acb3e to your computer and use it in GitHub Desktop.
Save disouzam/199e15f8b94f10c69c46cade8c9acb3e to your computer and use it in GitHub Desktop.
Bash configuration
# set -o xtrace
# https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
# Black 0;30 Dark Gray 1;30
# Blue 0;34 Light Blue 1;34
# Green 0;32 Light Green 1;32
# Cyan 0;36 Light Cyan 1;36
# Red 0;31 Light Red 1;31
# Purple 0;35 Light Purple 1;35
# Brown 0;33 Yellow 1;33
# Light Gray 0;37 White 1;37
# export GIT_PS1_SHOWDIRTYSTATE=1
# export GIT_PS1_SHOWUNTRACKEDFILES=1
# export GIT_PS1_SHOWSTASHSTATE=1
# export GIT_PS1_SHOWCONFLICTSTATE='yes'
# export GIT_PS1_SHOWUPSTREAM="verbose git"
# export GIT_PS1_DESCRIBE_STYLE="branch"
# export GIT_PS1_SHOWCOLORHINTS=1
# BLUE="\[\033[0;34m\]"
# LIGHT_BLUE="\[\033[1;34m\]"
# RED="\[\033[0;31m\]"
# LIGHT_RED="\[\033[1;31m\]"
# LIGHT_PURPLE="\[\033[1;35m\]"
# GREEN="\[\033[0;32m\]"
# YELLOW="\[\033[1;33m\]"
# WHITE="\[\033[1;37m\]"
# NO_COLOUR="\[\033[0m\]"
# # Source: https://askubuntu.com/questions/16424/displaying-a-new-line-on-the-prompt/1197614#1197614
# function newline() {
# printf "\n "
# }
# function current_date() {
# printf "$(date +%^b-%d' '%H:%M:%S)"
# }
# function current_branch() {
# bash ~/.git-prompt.sh
# branchname=$(__git_ps1 " (%s)")
# branchname="${branchname/\(/}"
# branchname="${branchname/\)/}"
# echo $branchname
# }
# function ps1base2() {
# local ps1base="\$(newline)$GREEN\! $YELLOW$(current_date) $GREEN\u$WHITE@\h $LIGHT_PURPLE\w $NO_COLOUR\$(newline)"
# local result=''
# result="$ps1base"
# branch_name=`current_branch`
# emptybranchstr="<>"
# if test "<`current_branch`>" != "$emptybranchstr";
# then
# result+="$NO_COLOUR"
# result+="Branch:"
# result+=" $branch_name"
# result+="$NO_COLOUR\$(newline)"
# fi
# if test "<`current_branch`>" == "$emptybranchstr";
# then
# result+="$NO_COLOUR"
# result+="This is not a git repository."
# result+="$NO_COLOUR\$(newline)"
# fi
# echo $result
# }
# function check_virtual_env() {
# # Source https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
# virtualenv=$VIRTUAL_ENV
# virtualenv="$(echo "$virtualenv" | sed s/'\\'/'\/'/g)"
# if [[ $VIRTUAL_ENV != '' ]]
# then
# ps1virtual_env="$(ps1base2)Virtual env: $LIGHT_BLUE$virtualenv$NO_COLOUR - Version: $YELLOW$(python --version)$NO_COLOUR$(newline)"
# ps1final=$ps1virtual_env
# else
# ps1final=`ps1base2`
# fi
# ps1final+='$ '
# PS1=$ps1final
# }
# # Source: https://stackoverflow.com/questions/15116806/how-can-i-see-all-of-the-bash-history/15117345#15117345
# shopt -s histappend
# PROMPT_COMMAND="check_virtual_env; history -n; history -a; history -c; history -r;"
# HISTTIMEFORMAT="%Y-%m-%d %T "
# unset HISTFILESIZE
# HISTSIZE=100
alias c=clear
alias ch='rm ~/.bash_history'
alias cls=clear
alias dir='dir -a -C --color -l --group-directories-first --quote-name'
alias h='history'
alias md='mkdir'
alias otag='gitk --tags --simplify-by-decoration'
alias padd='poetry add'
alias pel='poetry env list'
alias pinfo='poetry env info'
alias pinit='poetry init'
alias pid='poetry install --no-root'
alias plock='poetry lock'
alias pshell='poetry shell'
alias puse='poetry env use'
alias restart='. ~/.bashrc'
alias sl='streamlit'
alias uptag='git show-ref --tags -s -d | grep 'refs' > list-of-tags.txt'
alias uptag2='git show-ref --tags | grep 'refs' > list-of-tags.txt'
alias uptag3='header="Tags and its commit SHAs:\n" && echo -e $header > list-of-tags.txt && git show-ref --tags -s -d | grep refs >> list-of-tags.txt && header="\n\nTag messages:\n" && echo -e $header >> list-of-tags.txt && git tag --list -n10 >> list-of-tags.txt'
alias actvenv='echo $VIRTUAL_ENV && python --version'
alias vs2022='start devenv.exe'
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
# https://medium.com/@fdikmen/setting-terminal-encoding-to-utf-8-on-macos-and-linux-10f3ea4b037a
export LANG=pt_BR.UTF-8
@disouzam
Copy link
Author

Typing alias in bash list all configured alias in .bashrc

@disouzam
Copy link
Author

disouzam commented Oct 22, 2023

Added a new alias to open gitk with dangling commits

alias dangcom='gitk --all --date-order '$(git fsck --no-progress --no-reflogs | \grep 'dangling commit' | \gawk '{printf $3; printf " "}')''

References:

With adaptation coming from:

@disouzam
Copy link
Author

The drawback of this alias is that it gets expanded on shell starts - so, if a new dangling commit was created after the shell started, a new shell must be opened to get the full list of dangling commits.

@disouzam
Copy link
Author

In this last version, I updated a custom designed prompt configuration, triggered by a need from using Poetry and its custom shell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment