Last active
December 7, 2022 08:45
-
-
Save hvanmegen/6ca3fd3689b0d756468a55fcbbb9e0d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
tabs 4 | |
# Touch either one of these two files to disable this terminal addition | |
if [ ! -f ~/.config/no_niceterm ] && [ ! -f ~/.no_niceterm ]; then | |
if [ -x /sbin/ip ]; then | |
EXT_IP=$(ip route get 8.8.8.8 | awk -v ORS="" '{print $7}') | |
fi | |
if [ -x /bin/hostname ]; then | |
HOSTNAME_F=$(hostname -f) | |
fi | |
alias duh="echo 'scanning folders...' ; echo ; du -h --max-depth=1 | sort -h" | |
alias pu="phpunit" | |
alias pa="php artisan" | |
alias pico="nano" | |
if [[ $EUID == 0 ]]; then | |
SHOWIP=1; | |
alias nr="nginx -t && service nginx restart" | |
fi | |
function parse_git_remote { git config --get remote.origin.url 2>/dev/null | awk '{print $0" "}' ;} | |
function parse_git_branch { git branch --no-color 2>/dev/null | sed -e '/^[^*] /d' -e 's/* \(.*\)/\1/' | awk '{print $0"\\n"}' ;} | |
extract () { | |
if [ ! -z $1 ] ; then | |
if [ -f $1 ] ; then | |
case $1 in | |
*.xz) tar xf $1 ;; | |
*.tar.bz2) tar xvjf $1 ;; | |
*.tar.gz) tar xvzf $1 ;; | |
*.bz2) bunzip2 $1 ;; | |
*.rar) unrar x $1 ;; | |
*.gz) gunzip $1 ;; | |
*.tar) tar xvf $1 ;; | |
*.tbz2) tar xvjf $1 ;; | |
*.tgz) tar xvzf $1 ;; | |
*.zip) unzip $1 ;; | |
*.Z) uncompress $1 ;; | |
*.7z) 7z x $1 ;; | |
*) echo "unknown archive: '$1'" ;; | |
esac | |
else | |
echo "'$1' is not a valid file!" | |
fi | |
else | |
echo "extract what?" | |
fi | |
} | |
set_prompt () { | |
Last_Command=$? # Must come first! | |
Gray='\[\e[01;30m\]' | |
Red='\[\e[01;31m\]' | |
Green='\[\e[01;32m\]' | |
Yellow='\[\e[01;33m\]' | |
Blue='\[\e[01;34m\]' | |
Purple='\[\e[01;35m\]' | |
Lightblue='\[\e[01;36m\]' | |
White='\[\e[01;37m\]' | |
Reset='\[\e[01;00m\]' | |
FancyX='\342\234\227' | |
Checkmark='\342\234\223' | |
PS1="" | |
if [[ $EUID == 0 ]]; then | |
if [[ $SHOWIP == 1 ]]; then | |
PS1="$Yellow${EXT_IP}$Reset " | |
fi | |
PS1+="$Red\\u@${HOSTNAME_F}" | |
else | |
if [[ $SHOWIP == 1 ]]; then | |
PS1="$Lightblue${EXT_IP}$Reset " | |
fi | |
PS1+="$Green\\u@${HOSTNAME_F}" | |
fi | |
PS1+="$White:" | |
PS1+="$Blue\\w" | |
if [ -x "$(command -v git)" ]; then | |
PS1+="$Reset\n" | |
PS1+="$Purple$(parse_git_remote)" | |
PS1+="$Yellow$(parse_git_branch)" | |
else | |
PS1+="$Reset\n" | |
fi | |
if [[ $EUID == 0 ]]; then | |
PS1+="$Red\\\$$Reset> " | |
else | |
PS1+="$Green\\\$$Reset> " | |
fi | |
echo -ne "\033]0;${USER}@${HOSTNAME_F}:${PWD/$HOME/~}\007"; | |
} | |
PROMPT_COMMAND='set_prompt' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment