1
0
Fork 0
mirror of https://gitlab.com/dwt1/dotfiles.git synced 2023-02-13 20:55:19 -05:00
dwt1--dotfiles/.bashrc

256 lines
8.4 KiB
Bash
Raw Normal View History

2021-03-20 10:15:41 -04:00
# ____ _____
2019-01-15 16:07:06 -05:00
# | _ \_ _| Derek Taylor (DistroTube)
2019-01-17 18:33:18 -05:00
# | | | || | http://www.youtube.com/c/DistroTube
2021-03-20 10:15:41 -04:00
# | |_| || | http://www.gitlab.com/dwt1/
2020-02-17 01:17:21 -05:00
# |____/ |_|
#
2020-07-17 21:01:04 -04:00
# My bash config. Not much to see here; just some pretty standard stuff.
2020-08-11 18:27:59 -04:00
### EXPORT
export TERM="xterm-256color" # getting proper colors
export HISTCONTROL=ignoredups:erasedups # no duplicate entries
export ALTERNATE_EDITOR="" # setting for emacsclient
export EDITOR="emacsclient -t -a ''" # $EDITOR use Emacs in terminal
export VISUAL="emacsclient -c -a emacs" # $VISUAL use Emacs in GUI mode
### SET MANPAGER
### Uncomment only one of these!
### "bat" as manpager
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
### "vim" as manpager
# export MANPAGER='/bin/bash -c "vim -MRn -c \"set buftype=nofile showtabline=0 ft=man ts=8 nomod nolist norelativenumber nonu noma\" -c \"normal L\" -c \"nmap q :qa<CR>\"</dev/tty <(col -b)"'
### "nvim" as manpager
# export MANPAGER="nvim -c 'set ft=man' -"
2019-01-15 16:07:06 -05:00
2020-12-05 16:30:52 -05:00
### SET VI MODE ###
# Comment this line out to enable default emacs-like bindings
2020-08-11 18:27:59 -04:00
set -o vi
2020-10-13 20:35:02 -04:00
bind -m vi-command 'Control-l: clear-screen'
bind -m vi-insert 'Control-l: clear-screen'
2020-08-11 18:27:59 -04:00
# If not running interactively, don't do anything
2019-01-15 16:07:06 -05:00
[[ $- != *i* ]] && return
2020-08-11 18:27:59 -04:00
### PROMPT
2020-12-05 16:30:52 -05:00
# This is commented out if using starship prompt
# PS1='[\u@\h \W]\$ '
2019-01-15 16:07:06 -05:00
2020-08-11 18:27:59 -04:00
### PATH
if [ -d "$HOME/.bin" ] ;
then PATH="$HOME/.bin:$PATH"
fi
if [ -d "$HOME/.local/bin" ] ;
then PATH="$HOME/.local/bin:$PATH"
fi
2019-01-15 16:07:06 -05:00
2020-12-12 10:09:31 -05:00
if [ -d "$HOME/Applications" ] ;
then PATH="$HOME/Applications:$PATH"
fi
2020-08-11 18:27:59 -04:00
### CHANGE TITLE OF TERMINALS
2019-01-15 16:07:06 -05:00
case ${TERM} in
2020-08-11 18:27:59 -04:00
xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|alacritty|st|konsole*)
2020-05-30 12:49:58 -04:00
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\007"'
;;
screen*)
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\033\\"'
;;
2019-01-15 16:07:06 -05:00
esac
2020-08-11 18:27:59 -04:00
### SHOPT
shopt -s autocd # change to named directory
shopt -s cdspell # autocorrects cd misspellings
shopt -s cmdhist # save multi-line commands in history as single line
shopt -s dotglob
shopt -s histappend # do not overwrite history
shopt -s expand_aliases # expand aliases
shopt -s checkwinsize # checks term size when bash regains control
2019-01-15 16:07:06 -05:00
2020-08-11 18:27:59 -04:00
#ignore upper and lowercase when TAB completion
bind "set completion-ignore-case on"
2019-01-15 16:07:06 -05:00
2020-08-11 18:27:59 -04:00
### ARCHIVE EXTRACTION
# usage: ex <file>
2019-01-15 16:07:06 -05:00
ex ()
{
if [ -f "$1" ] ; then
2019-01-15 16:07:06 -05:00
case $1 in
2020-02-17 00:15:06 -05:00
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
2020-08-11 18:27:59 -04:00
*.rar) unrar x $1 ;;
2020-02-17 00:15:06 -05:00
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1;;
*.7z) 7z x $1 ;;
2020-08-11 18:27:59 -04:00
*.deb) ar x $1 ;;
*.tar.xz) tar xf $1 ;;
2021-03-20 10:15:41 -04:00
*.tar.zst) unzstd $1 ;;
2020-02-17 00:15:06 -05:00
*) echo "'$1' cannot be extracted via ex()" ;;
2019-01-15 16:07:06 -05:00
esac
else
echo "'$1' is not a valid file"
fi
}
2020-02-17 01:17:21 -05:00
### ALIASES ###
2020-03-23 00:41:03 -04:00
2020-03-27 15:50:01 -04:00
# root privileges
alias doas="doas --"
2020-02-17 01:17:21 -05:00
# navigation
up () {
local d=""
local limit="$1"
# Default to limit of 1
if [ -z "$limit" ] || [ "$limit" -le 0 ]; then
limit=1
fi
for ((i=1;i<=limit;i++)); do
d="../$d"
done
# perform cd. Show error if cd fails
if ! cd "$d"; then
echo "Couldn't go up $limit dirs.";
fi
}
2020-02-17 01:17:21 -05:00
2020-06-19 23:43:40 -04:00
# vim and emacs
2020-08-18 17:16:40 -04:00
alias vim="nvim"
2020-06-19 23:43:40 -04:00
alias em="/usr/bin/emacs -nw"
2020-08-18 17:16:40 -04:00
alias emacs="emacsclient -c -a 'emacs'"
2020-11-02 19:56:51 -05:00
alias doomsync="~/.emacs.d/bin/doom sync"
alias doomdoctor="~/.emacs.d/bin/doom doctor"
alias doomupgrade="~/.emacs.d/bin/doom upgrade"
alias doompurge="~/.emacs.d/bin/doom purge"
2020-08-18 17:16:40 -04:00
2020-02-17 01:17:21 -05:00
# Changing "ls" to "exa"
alias ls='exa -al --color=always --group-directories-first' # my preferred listing
alias la='exa -a --color=always --group-directories-first' # all files and dirs
alias ll='exa -l --color=always --group-directories-first' # long format
alias lt='exa -aT --color=always --group-directories-first' # tree listing
2020-08-11 18:27:59 -04:00
alias l.='exa -a | egrep "^\."'
# pacman and yay
alias pacsyu='sudo pacman -Syyu' # update only standard pkgs
alias yaysua='yay -Sua --noconfirm' # update only AUR pkgs (yay)
alias yaysyu='yay -Syu --noconfirm' # update standard pkgs and AUR pkgs (yay)
alias parsua='paru -Sua --noconfirm' # update only AUR pkgs (paru)
alias parsyu='paru -Syu --noconfirm' # update standard pkgs and AUR pkgs (paru)
alias unlock='sudo rm /var/lib/pacman/db.lck' # remove pacman lock
alias cleanup='sudo pacman -Rns (pacman -Qtdq)' # remove orphaned packages
# get fastest mirrors
alias mirror="sudo reflector -f 30 -l 30 --number 10 --verbose --save /etc/pacman.d/mirrorlist"
alias mirrord="sudo reflector --latest 50 --number 20 --sort delay --save /etc/pacman.d/mirrorlist"
alias mirrors="sudo reflector --latest 50 --number 20 --sort score --save /etc/pacman.d/mirrorlist"
alias mirrora="sudo reflector --latest 50 --number 20 --sort age --save /etc/pacman.d/mirrorlist"
2020-08-11 18:27:59 -04:00
# Colorize grep output (good for log files)
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
2020-08-20 19:33:03 -04:00
# confirm before overwriting something
alias cp="cp -i"
alias mv='mv -i'
alias rm='rm -i'
2020-02-17 01:17:21 -05:00
# adding flags
alias df='df -h' # human-readable sizes
alias free='free -m' # show sizes in MB
alias lynx='lynx -cfg=~/.lynx/lynx.cfg -lss=~/.lynx/lynx.lss -vikeys'
alias vifm='./.config/vifm/scripts/vifmrun'
2021-03-20 10:15:41 -04:00
alias ncmpcpp='ncmpcpp ncmpcpp_directory=$HOME/.config/ncmpcpp/'
2021-03-20 10:30:33 -04:00
alias mocp='mocp -M "$XDG_CONFIG_HOME"/moc -O MOCDir="$XDG_CONFIG_HOME"/moc'
2020-02-17 01:17:21 -05:00
# ps
alias psa="ps auxf"
alias psgrep="ps aux | grep -v grep | grep -i -e VSZ -e"
2020-08-18 17:16:40 -04:00
alias psmem='ps auxf | sort -nr -k 4'
alias pscpu='ps auxf | sort -nr -k 3'
# Merge Xresources
alias merge='xrdb -merge ~/.Xresources'
2020-08-18 17:16:40 -04:00
# git
alias addup='git add -u'
alias addall='git add .'
alias branch='git branch'
alias checkout='git checkout'
2020-08-20 19:33:03 -04:00
alias clone='git clone'
2020-08-18 17:16:40 -04:00
alias commit='git commit -m'
alias fetch='git fetch'
alias pull='git pull origin'
alias push='git push origin'
alias stat='git status' # 'status' is protected name so using 'stat' instead
2020-08-18 17:16:40 -04:00
alias tag='git tag'
alias newtag='git tag -a'
2020-08-11 18:27:59 -04:00
# get error messages from journalctl
alias jctl="journalctl -p 3 -xb"
# gpg encryption
# verify signature for isos
alias gpg-check="gpg2 --keyserver-options auto-key-retrieve --verify"
# receive the key of a developer
alias gpg-retrieve="gpg2 --keyserver-options auto-key-retrieve --receive-keys"
# youtube-dl
alias yta-aac="youtube-dl --extract-audio --audio-format aac "
alias yta-best="youtube-dl --extract-audio --audio-format best "
alias yta-flac="youtube-dl --extract-audio --audio-format flac "
alias yta-m4a="youtube-dl --extract-audio --audio-format m4a "
alias yta-mp3="youtube-dl --extract-audio --audio-format mp3 "
alias yta-opus="youtube-dl --extract-audio --audio-format opus "
alias yta-vorbis="youtube-dl --extract-audio --audio-format vorbis "
alias yta-wav="youtube-dl --extract-audio --audio-format wav "
alias ytv-best="youtube-dl -f bestvideo+bestaudio "
2020-08-18 17:16:40 -04:00
# switch between shells
# I do not recommend switching default SHELL from bash.
2020-08-18 17:16:40 -04:00
alias tobash="sudo chsh $USER -s /bin/bash && echo 'Now log out.'"
alias tozsh="sudo chsh $USER -s /bin/zsh && echo 'Now log out.'"
alias tofish="sudo chsh $USER -s /bin/fish && echo 'Now log out.'"
2020-02-17 01:17:21 -05:00
# bare git repo alias for dotfiles
alias config="/usr/bin/git --git-dir=$HOME/dotfiles --work-tree=$HOME"
2019-01-15 16:07:06 -05:00
2020-02-17 01:17:21 -05:00
# termbin
2019-03-09 18:52:05 -05:00
alias tb="nc termbin.com 9999"
2019-03-22 19:45:15 -04:00
2020-08-18 17:16:40 -04:00
# the terminal rickroll
alias rr='curl -s -L https://raw.githubusercontent.com/keroserene/rickrollrc/master/roll.sh | bash'
2021-01-17 18:15:26 -05:00
# Unlock LBRY tips
alias tips='lbrynet txo spend --type=support --is_not_my_input --blocking'
### DTOS ###
# Copy/paste all content of /etc/dtos over to home folder. A backup of config is created. (Be careful running this!)
alias dtoscopy='[ -d ~/.config ] || mkdir ~/.config && cp -Rf ~/.config ~/.config-backup-$(date +%Y.%m.%d-%H.%M.%S) && cp -rf /etc/dtos/* ~'
# Backup contents of /etc/dtos to a backup folder in $HOME.
alias dtosbackup='cp -Rf /etc/dtos ~/dtos-backup-$(date +%Y.%m.%d-%H.%M.%S)'
2020-03-20 13:13:52 -04:00
### RANDOM COLOR SCRIPT ###
2020-12-05 16:30:52 -05:00
# Get this script from my GitLab: gitlab.com/dwt1/shell-color-scripts
# Or install it from the Arch User Repository: shell-color-scripts
2020-12-01 16:54:57 -05:00
colorscript random
2020-10-23 21:39:58 -04:00
2020-12-01 16:54:57 -05:00
### BASH INSULTER ###
if [ -f /etc/bash.command-not-found ]; then
. /etc/bash.command-not-found
fi
2020-12-05 16:30:52 -05:00
### SETTING THE STARSHIP PROMPT ###
eval "$(starship init bash)"