Last active
July 23, 2022 20:34
-
-
Save jpdias/e052fcc385b46b7e8526eb9fb1a129b1 to your computer and use it in GitHub Desktop.
My bashrc file
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
# ~/.bashrc: executed by bash(1) for non-login shells. | |
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) | |
# for examples | |
# If not running interactively, don't do anything | |
case $- in | |
*i*) ;; | |
*) return ;; | |
esac | |
# check the window size after each command and, if necessary, | |
# update the values of LINES and COLUMNS. | |
shopt -s checkwinsize | |
# make less more friendly for non-text input files, see lesspipe(1) | |
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" | |
# set variable identifying the chroot you work in (used in the prompt below) | |
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then | |
debian_chroot=$(cat /etc/debian_chroot) | |
fi | |
# set a fancy prompt (non-color, unless we know we "want" color) | |
case "$TERM" in | |
xterm-color | *-256color) color_prompt=yes ;; | |
esac | |
if [ -n "$force_color_prompt" ]; then | |
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then | |
# We have color support; assume it's compliant with Ecma-48 | |
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such | |
# a case would tend to support setf rather than setaf.) | |
color_prompt=yes | |
else | |
color_prompt= | |
fi | |
fi | |
if [ "$color_prompt" = yes ]; then | |
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
else | |
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' | |
fi | |
unset color_prompt force_color_prompt | |
# If this is an xterm set the title to user@host:dir | |
case "$TERM" in | |
xterm* | rxvt*) | |
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" | |
;; | |
*) ;; | |
esac | |
# enable color support of ls and also add handy aliases | |
if [ -x /usr/bin/dircolors ]; then | |
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
alias ls='ls --color=auto' | |
#alias dir='dir --color=auto' | |
#alias vdir='vdir --color=auto' | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
fi | |
# colored GCC warnings and errors | |
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' | |
# some more ls aliases | |
alias ll='ls -alF' | |
alias la='ls -A' | |
alias l='ls -CF' | |
# 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$//'\'')"' | |
# Alias definitions. | |
if [ -f ~/.bash_aliases ]; then | |
. ~/.bash_aliases | |
fi | |
# enable programmable completion features (you don't need to enable | |
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile | |
# sources /etc/bash.bashrc). | |
if ! shopt -oq posix; then | |
if [ -f /usr/share/bash-completion/bash_completion ]; then | |
. /usr/share/bash-completion/bash_completion | |
elif [ -f /etc/bash_completion ]; then | |
. /etc/bash_completion | |
fi | |
fi | |
# Create missing directories in path | |
alias mkdir='mkdir -pv' | |
# Print full file path | |
alias path='readlink -e' | |
# Remove directories but ask nicely | |
alias rmm='rm -rvI' | |
# Copy directories but ask nicely | |
alias cpp='cp -R' | |
# add current directory to path | |
alias add-to-path='set -U fish_user_paths (pwd) $fish_user_paths' | |
# Human readable sizes (i.e. Mb, Gb etc) | |
alias df='df -h' | |
alias du='du -ch' | |
alias free='free -m' | |
alias xs='cd' | |
alias ...='cd ../..' | |
# Free space on physical drives | |
alias fs='df -h -x squashfs -x tmpfs -x devtmpfs' | |
# Lists disks | |
alias disks='lsblk -o HOTPLUG,NAME,SIZE,MODEL,TYPE | awk "NR == 1 || /disk/"' | |
# List partitions | |
alias partitions='lsblk -o HOTPLUG,NAME,LABEL,MOUNTPOINT,SIZE,MODEL,PARTLABEL,TYPE | grep -v loop' | |
# Size of file or directory | |
alias sizeof="du -hs" | |
# Connect to wifi | |
alias connect=nmtui | |
# Prevent locking untill next reboot | |
alias lockblock='killall xautolock; xset s off; xset -dpms; echo ok' | |
# Save file with provided name | |
alias wget='wget --content-disposition' | |
# Resolve aliases after sudo | |
alias sudo='sudo ' | |
alias ff="find $PWD -iname" | |
alias untar="tar -vxzf" | |
alias getmicro='curl https://getmic.ro | bash && sudo mv ./micro /usr/local/bin/' | |
# Aliases | |
mkcd() { | |
mkdir "$1" | |
cd "$1" | |
} | |
# Open file in GUI associated application | |
alias open=xdg-open | |
alias ll='ls -lh' | |
# Serves current directory on 8080 port | |
alias server-here='twistd -no web --path=.' | |
# Human readable sizes (i.e. Mb, Gb etc) | |
alias df='df -h' | |
alias du='du -ch' | |
alias free='free -g' | |
# Adding repositories without prompt, automatically adding sudo | |
add-apt-repository() { | |
sudo add-apt-repository --yes $* | |
sudo apt-get update | |
} | |
# Prepend `sudo` to `nano` command if file is not editable by current user | |
nano() { | |
if [ -w "$1" ]; then | |
/bin/nano $* | |
else | |
sudo /bin/nano $* | |
fi | |
} | |
# Make file executable, then run it | |
run() { | |
chmod +x "$1" | |
exec "./$1" & | |
} | |
bak() { | |
mv "$1" "$(basename $1).bak" | |
} | |
# If Sublime Text installed - use it istead of Gedit | |
if hash subl 2>/dev/null; then | |
alias gedit=subl | |
fi | |
# Add sudo if forgotten | |
if [ $UID -ne 0 ]; then | |
alias susp='sudo /usr/sbin/pm-suspend' | |
alias apt-get='sudo apt-get' | |
alias dpkg='sudo dpkg' | |
alias apt='sudo apt' | |
fi | |
alias poweroff='shutdown -P now' | |
alias reboot='shutdown -r now' | |
# Setup prompt | |
PS1='\[$(tput bold)\]\[\033[38;5;243m\][\w❯\n$ \[$(tput sgr0)\]' | |
# History settings | |
shopt -s histappend | |
shopt -s cmdhist | |
HISTSIZE=500000 | |
HISTFILESIZE=100000 | |
HISTCONTROL="erasedups:ignoreboth" | |
PROMPT_COMMAND='history -a' | |
export HISTIGNORE="&:[ ]*:exit:ls:bg:fg:history:clear" | |
# functions | |
# generate a password | |
passgen() { | |
tr </dev/urandom -dc _A-Z-a-z-0-9 | head -c${1:-16} | |
echo | |
} | |
# calculator | |
function calc() { | |
echo "${1}" | bc -l | |
} | |
# decompress | |
extract() { | |
if [ -z "$1" ]; then | |
# display usage if no parameters given | |
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>" | |
else | |
if [ -f $1 ]; then | |
# NAME=${1%.*} | |
# mkdir $NAME && cd $NAME | |
case $1 in | |
*.tar.bz2) tar xvjf $1 ;; | |
*.tar.gz) tar xvzf $1 ;; | |
*.tar.xz) tar xvJf $1 ;; | |
*.lzma) unlzma $1 ;; | |
*.bz2) bunzip2 $1 ;; | |
*.rar) unrar x -ad $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 ;; | |
*.xz) unxz $1 ;; | |
*.exe) cabextract $1 ;; | |
*) echo "extract: '$1' - unknown archive method" ;; | |
esac | |
else | |
echo "$1 - file does not exist" | |
fi | |
fi | |
} | |
alias update='sudo apt-get update && sudo apt-get upgrade' | |
alias clean='sudo apt-get autoremove' | |
# get public ip | |
function myip { | |
wget http://ipinfo.io/ip -qO - | |
} | |
# highlight IP pattern | |
function highlight_ip() { | |
perl -pe 's/((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])/\e[1;31m$&\e[0m/g' | |
} | |
#internal ip | |
function ip() { | |
ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk '{ print $2 }' | |
} | |
#ipinfo | |
ipinfo() { | |
curl ipinfo.io/$1 | |
echo | |
} | |
# public file sharing | |
function transfer() { | |
if [ $# -eq 0 ]; then | |
echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md" | |
return 1 | |
fi | |
tmpfile=$(mktemp -t transferXXX) | |
if tty -s; then | |
basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g') | |
curl --progress-bar -H "Max-Downloads: 6" -H "Max-Days: 10" --upload-file "$1" "https://transfer.sh/$basefile" >>$tmpfile | |
else | |
curl --progress-bar -H "Max-Downloads: 6" -H "Max-Days: 10" --upload-file "-" "https://transfer.sh/$1" >>$tmpfile | |
fi | |
cat $tmpfile | |
rm -f $tmpfile | |
} | |
# color table | |
function color_test() { | |
T='gYw' # The test text | |
echo -e "\n 40m 41m 42m 43m 44m 45m 46m 47m" | |
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' ' 36m' '1;36m' ' 37m' '1;37m'; do | |
FG=${FGs// /} | |
echo -en " $FGs \033[$FG $T " | |
for BG in 40m 41m 42m 43m 44m 45m 46m 47m; do | |
echo -en "$EINS \033[$FG\033[$BG $T \033[0m\033[$BG \033[0m" | |
done | |
echo | |
done | |
echo | |
} | |
## Show unmerged branches in GIT | |
function unmerged { | |
git branch -r --no-merged | grep -v HEAD | xargs -L1 git --no-pager log --pretty=tformat:'%Cgreen%d%Creset - %h by %an (%Cblue%ar%Creset)' -1 | |
} | |
function cdd { | |
cd $(dirname $1) | |
} | |
function recured { | |
[ -z $1 ] && echo "usage recured [NAME] [DEPTH] [PROGRAM]" | |
find . -maxdepth ${2:-2} -type f -name "$1" | xargs -t "${3:-subl3}" 2>&1 | |
} | |
# enable programmable completion features (you don't need to enable | |
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile | |
# sources /etc/bash.bashrc). | |
if ! shopt -oq posix; then | |
if [ -f /usr/share/bash-completion/bash_completion ]; then | |
. /usr/share/bash-completion/bash_completion | |
elif [ -f /etc/bash_completion ]; then | |
. /etc/bash_completion | |
fi | |
fi | |
# Alias definitions. | |
# You may want to put all your additions into a separate file like | |
# ~/.bash_aliases, instead of adding them here directly. | |
# See /usr/share/doc/bash-doc/examples in the bash-doc package. | |
if [ -f ~/.bash_aliases ]; then | |
. ~/.bash_aliases | |
fi | |
# enable color support of ls and also add handy aliases | |
if [ -x /usr/bin/dircolors ]; then | |
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
alias ls='ls --color=always' | |
alias dir='dir --color=always' | |
alias vdir='vdir --color=always' | |
alias grep='grep --color=always' | |
alias fgrep='fgrep --color=always' | |
alias egrep='egrep --color=always' | |
fi | |
eval "$(starship init bash)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment