dotfiles/files/bash/.bashrc

643 lines
25 KiB
Bash
Raw Permalink Normal View History

2015-06-14 19:25:31 +00:00
#!/bin/bash
pathadd() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="${PATH:+"$PATH:"}$1"
fi
}
2019-12-16 19:58:43 +00:00
# Read a gemfile contents
# https://stackoverflow.com/a/43298099
gemread() {
tar --to-stdout -xf "$1" data.tar.gz | tar -zt
}
2015-06-22 07:42:20 +00:00
pathadd '/home/nemo/bin'
2019-02-10 06:35:38 +00:00
pathadd '/home/nemo/projects/go/bin'
2019-09-05 12:21:07 +00:00
pathadd '/bin'
pathadd '/snap/bin'
pathadd /home/nemo/.local/share/junest/bin
2019-12-16 19:58:43 +00:00
export GPG_TTY="$(tty)"
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
2015-06-14 19:25:31 +00:00
2021-02-09 07:47:09 +00:00
function gemls(){
tar --to-stdout -xf "$1" data.tar.gz | tar -zt
}
2020-09-14 10:24:26 +00:00
alias adb.run='apktool build src/ -o patched.apk && java -jar ~/apps/uber-apk-signer-1.1.0.jar -a patched.apk && adb install -r -d patched-aligned-debugSigned.apk && adb shell monkey -p '$1' -v 1'
2019-12-16 19:58:43 +00:00
alias mk='microk8s.kubectl'
alias settings='env XDG_CURRENT_DESKTOP=GNOME gnome-control-center'
2018-06-22 13:22:55 +00:00
alias watch='watch '
alias xclip='xclip -selection c'
alias sl=ls
alias dynamodump='docker run bchew/dynamodump /usr/local/bin/dynamodump'
2021-08-24 09:14:39 +00:00
alias dh='du -d1 -h'
2018-11-01 16:23:02 +00:00
alias wine32='WINEARCH=win32 WINEPREFIX=~/win32 wine'
2021-08-24 09:14:39 +00:00
alias signal_update='podman run docker.io/captn3m0/signal-arch-builder'
2019-05-08 06:00:45 +00:00
alias kc='kapitan compile'
2019-09-14 21:37:44 +00:00
# https://tizardsbriefcase.com/1059/linux/remove-query-string-filename-wget
alias clean.filenames='for file in *; do mv "$file" "${file%%\?*}"; done'
alias dunst.pause='notify-send "DUNST_COMMAND_PAUSE"'
alias dunst.resume='notify-send "DUNST_COMMAND_RESUME"'
2021-08-24 09:14:39 +00:00
alias sp="docker exec -it steampipe steampipe "
alias steampipe.service="docker run \
-p 9193:9193 \
--name steampipe \
--mount type=bind,source=/home/nemo/.config/steampipe,target=/home/steampipe/.steampipe/config \
--mount type=volume,source=steampipe_data,target=/home/steampipe/.steampipe/db/12.1.0/data \
--mount type=volume,source=steampipe_internal,target=/home/steampipe/.steampipe/internal \
--mount type=volume,source=steampipe_logs,target=/home/steampipe/.steampipe/logs \
--mount type=volume,source=steampipe_plugins,target=/home/steampipe/.steampipe/plugins \
turbot/steampipe service start --foreground"
function aur.make() {
find . -maxdepth 1 -iregex '.*\.\(bz2\|tar\|zip\|deb\|xz\|part\|rpm\|gz\|zst\|AppImage\|pacman\|jar\)$' -delete
makepkg --printsrcinfo > .SRCINFO
makepkg -sric
}
2018-06-22 13:22:55 +00:00
# ... or force ignoredups and ignorespace
pathadd '/sbin'
pathadd '/home/nemo/projects/scripts/'
pathadd "$HOME/.phpenv/bin"
pathadd "$HOME/apps/ec2/bin"
2021-05-29 09:15:12 +00:00
pathadd "$HOME/.gem/ruby/3.0.0/bin"
2019-04-09 20:54:15 +00:00
# needs a kubectl upgrade
pathadd "$HOME/.krew/bin"
2019-04-13 16:09:56 +00:00
pathadd "$HOME/.local/bin"
2019-04-09 20:54:15 +00:00
2019-12-16 19:58:43 +00:00
# slows shell for now.
source <(kubectl completion bash)
# Enable kubectl completion with k
complete -F __start_kubectl k
2019-04-09 20:54:15 +00:00
# https://substrakt.com/journal/easy-peasy-composer-local-package-symlink-composer-link/
composer-link() {
jq '.repositories |= [{"type": "path", "url": "'$1'", "options": {"symlink": true}}] + . ' composer.json > composer.tmp.json && mv composer.tmp.json composer.json
packageName=$(jq -r '.name' $1/composer.json)
composer require $packageName @dev
}
composer-unlink() {
git checkout composer.json composer.lock
composer update
}
2018-06-22 13:22:55 +00:00
2020-07-02 18:17:41 +00:00
# These 2 methods change the color scheme for my:
2021-01-19 07:20:26 +00:00
# 1. Editor (sublime text)
2020-07-02 18:17:41 +00:00
# 2. Terminal (alacritty)
# 3. bat
# 4. Monitor brightness (only one of the monitors). See https://github.com/rockowitz/ddcutil/issues/140
2021-01-19 07:20:26 +00:00
# 5. Gtk theme
2020-07-02 18:17:41 +00:00
export ALACRITTY_COLOR_DIR=/home/nemo/projects/personal/dotfiles/files/themes/.config/alacritty/themes/colors
2021-01-18 12:58:46 +00:00
export BAT_THEME="Solarized (light)"
2021-05-29 09:15:12 +00:00
GTK_THEME_dark="NumixSolarizedDarkRed"
2021-01-19 07:46:30 +00:00
GTK_THEME_light="NumixSolarizedLightGreen"
BRIGHTNESS_dark=0
BRIGHTNESS_light=99
2020-09-14 10:24:26 +00:00
2021-01-19 07:46:30 +00:00
function colorchange() {
export BAT_THEME="Solarized ($1)"
2021-01-19 07:20:26 +00:00
echo "✔️ bat"
2021-03-09 19:57:47 +00:00
alacritty-colorscheme -C "$ALACRITTY_COLOR_DIR" apply "base16-solarized-$1.yml"
2021-01-19 07:20:26 +00:00
echo "✔️ alacritty"
2021-01-19 07:46:30 +00:00
gtk_theme="GTK_THEME_$1"
xfconf-query -c xsettings -p /Net/ThemeName -s "${!gtk_theme}"
2021-01-19 07:20:26 +00:00
echo "✔️ gtk"
2021-08-24 09:14:39 +00:00
# subl_settings="/home/nemo/.config/sublime-text-3/Packages/User/Preferences.sublime-settings"
# strip-json-comments "$subl_settings" | jq ".color_scheme=\"Packages/Solarized Color Scheme/Solarized ($1).sublime-color-scheme\"" > /tmp/sublime.json
# mv /tmp/sublime.json "$subl_settings"
# echo "✔️ sublime"
2021-01-19 07:20:26 +00:00
2021-01-19 07:46:30 +00:00
brightness="BRIGHTNESS_$1"
if [[ $(xrandr --listmonitors|grep 2560) ]]; then
2021-01-19 07:46:30 +00:00
ddcutil --model "LG ULTRAWIDE" setvcp 0x10 ${!brightness}
fi
2021-01-19 07:20:26 +00:00
echo "✔️ monitor"
2020-07-02 18:17:41 +00:00
}
2021-01-19 07:46:30 +00:00
alias dark="colorchange dark"
alias light="colorchange light"
2020-07-02 18:17:41 +00:00
2020-12-20 16:25:02 +00:00
# https://prefetch.net/blog/2020/07/14/decoding-json-web-tokens-jwts-from-the-linux-command-line/
2021-05-29 09:15:12 +00:00
# This puts them in bash history, so be careful
2020-12-20 16:25:02 +00:00
jwtd() {
if [[ -x $(command -v jq) ]]; then
jq -R 'split(".") | .[0],.[1] | @base64d | fromjson' <<< "${1}"
echo "Signature: $(echo "${1}" | awk -F'.' '{print $3}')"
fi
}
2020-06-15 13:51:26 +00:00
if [ -f /usr/sbin/virtualenvwrapper.sh ]; then
export WORKON_HOME=~/.virtualenvs
export VIRTUALENVWRAPPER_SCRIPT=/usr/sbin/virtualenvwrapper.sh
source /usr/sbin/virtualenvwrapper_lazy.sh
fi
2018-06-22 13:22:55 +00:00
alias sublime='/usr/bin/sublime-text'
alias subl3=subl
alias chrome='chromium-browser'
alias gp='git push'
alias subtitles='subliminal -p addic7ed -l en -s -- $1'
alias pu='phpunit'
alias ghpr='gh pull-request'
alias ssdr='sudo systemctl daemon-reload'
2018-12-18 06:55:53 +00:00
alias cat='bat'
2019-09-05 12:21:07 +00:00
alias fomu.setup='export PATH=/home/nemo/apps/fomu/bin:$PATH'
2018-06-22 13:22:55 +00:00
# Gets list of all packages from AUR sorted by Size
2019-01-26 15:29:16 +00:00
alias aur.list='expac -H M "%m\t%n" | sort -h > /tmp/expac.txt && pacman -Qqm > /tmp/aur.txt && grep --color=never -w -F -f /tmp/aur.txt /tmp/expac.txt'
# Same as above, but all packages (except AUR)
alias package.list='expac -sH M "%-30n %m" | sort -hk 2'
2020-06-15 13:51:26 +00:00
alias package.owns='pacman -F'
2020-09-14 10:24:26 +00:00
# Download size of all packages marked for upgrade
alias package.dlsize='expac -S -H M '%k\t%n' $(pacman -Qqu) | sort -sh'
2018-11-01 16:23:02 +00:00
# To list the packages marked for upgrade with their download size
2019-01-26 15:29:16 +00:00
alias upgrade.size='pacman -Quq|xargs expac -SH M "%k\t%n" | sort -sh'
2018-11-01 16:23:02 +00:00
2018-06-22 13:22:55 +00:00
# https://github.com/chef/inspec
2021-08-24 09:14:39 +00:00
function inspec { podman run -it --rm -v $(pwd):/share chef/inspec $@; }
# Most common invocation: terraform.docs markdown --html=false --anchor=false --show "outputs"
function terraform.docs { podman run -it --rm -u $(id -u) -v $(pwd):/src quay.io/terraform-docs/terraform-docs:0.14.1 $@ /src; }
2019-04-13 16:09:56 +00:00
2021-04-20 12:27:45 +00:00
# Run as pingen N where N = Number of digits in PIN
2020-09-14 10:24:26 +00:00
function pingen { pwgen -1Avs -r=qwertyuiopasdfghjklzxcvbnm "$1"; }
2021-04-20 12:27:45 +00:00
# Sort a file in-place
2020-12-20 16:25:02 +00:00
function sortinplace { sort -o "$1" "$1"; }
2021-05-26 17:53:38 +00:00
function download_as_pdf {
rdrview --template "title,body" "$1" -H | tidy | pandoc --from html --pdf-engine=xelatex -o "$2"
}
2021-08-24 09:14:39 +00:00
alias kapitan='podman run -t --rm -u $(id -u) -v $(pwd):/src:delegated deepmind/kapitan'
2018-06-22 13:22:55 +00:00
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
force_color_prompt=yes
color_prompt=yes
export TERM=xterm-256color
# 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
2018-09-20 12:10:06 +00:00
# Drone related stuff
export DRONE_SERVER=https://drone.razorpay.com
2018-06-22 13:22:55 +00:00
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# k8s
alias k='kubectl'
alias kontext='kubectl config use-context'
alias kgpa='kubectl get pods --all-namespaces'
2019-12-16 19:58:43 +00:00
alias kgp='kubectl get pods -o wide'
2018-06-22 13:22:55 +00:00
alias kgpn='kubectl get pods -o wide -n '
alias kno='kubectl get nodes'
# https://twitter.com/indradhanush92/status/1003493096158420992
# kubectl and minikube completion is moved to /etc/bash_completion.d/
2018-04-26 10:30:01 +00:00
2017-11-22 09:55:50 +00:00
function kpssh() { kubectl exec -it $1 -n $2 sh ; }
function kcssh() { kubectl exec -it $1 -n $2 -c $3 sh ; }
function klog() { kubetail $1 -n $1 ; }
function kne() {
2018-04-26 10:30:01 +00:00
kubectl get events -n $1 --sort-by='.metadata.creationTimestamp' \
-o 'go-template={{range .items}}{{.involvedObject.name}}{{"\t"}}{{.involvedObject.kind}}{{"\t"}}{{.message}}{{"\t"}}{{.reason}}{{"\t"}}{{.type}}{{"\t"}}{{.firstTimestamp}}{{"\n"}}{{end}}'
2018-04-26 10:30:01 +00:00
}
2017-11-22 09:55:50 +00:00
2021-01-19 09:27:03 +00:00
# Export a secret automatically with the filename on pass
2018-09-20 12:10:06 +00:00
function gettoken() {
export "`basename $1`"="$(pass show $1)"
}
2017-12-30 06:00:34 +00:00
# Get inotify listener counts
function inotifytop() {
for foo in /proc/*/fd/*; do readlink -f $foo; done |grep inotify |cut -d/ -f3 |xargs -I '{}' -- ps --no-headers -o '%p %U %a' -p '{}' |uniq -c |sort -n
}
2020-06-15 13:51:26 +00:00
## COMPLETION SCRIPTS
2012-09-22 00:30:00 +00:00
if [[ -f /etc/bash_completion ]] && ! shopt -oq posix; then
2020-01-05 08:11:29 +00:00
. /etc/bash_completion
2012-09-22 00:30:00 +00:00
fi
2020-01-05 08:11:29 +00:00
2020-06-15 13:51:26 +00:00
if [[ -f /usr/share/bash-completion/completions/pipenv ]] && ! shopt -oq posix; then
. /usr/share/bash-completion/completions/pipenv
fi
2020-01-05 08:11:29 +00:00
if [[ -f /usr/share/bash-completion/completions/pass ]] && ! shopt -oq posix; then
. /usr/share/bash-completion/completions/pass
2012-09-22 00:30:00 +00:00
fi
2017-12-30 06:00:34 +00:00
2021-03-16 06:39:06 +00:00
if [[ -f /usr/share/bash-completion/completions/npm ]] && ! shopt -oq posix; then
. /usr/share/bash-completion/completions/npm
fi
if [[ -f /usr/share/bash-completion/completions/poetry ]] && ! shopt -oq posix; then
. /usr/share/bash-completion/completions/poetry
fi
2020-06-15 13:51:26 +00:00
if [[ -f /usr/share/doc/pkgfile/command-not-found.bash ]] && ! shopt -oq posix; then
. /usr/share/doc/pkgfile/command-not-found.bash
fi
2021-02-26 08:31:52 +00:00
if [[ -f /usr/share/git/completion/git-completion.bash ]] && ! shopt -oq posix; then
. /usr/share/git/completion/git-completion.bash
fi
2022-01-16 18:45:34 +00:00
if [[ -f /etc/bash_completion.d/pdm.bash-completion ]] && ! shopt -oq posix; then
. /etc/bash_completion.d/pdm.bash-completion
fi
2012-09-22 00:30:00 +00:00
function smallmkv() { ffmpeg -i "$1" -b 1000k -acodec libmp3lame -vcodec libx264 -ar 44100 -ab 56k -ac 2 -vpre fast -crf 24 \ "$1.mkv" ;}
2018-04-16 17:46:05 +00:00
export LC_ALL=en_US.utf8
export LC_ALL=en_US.utf8
export LANG=C
2021-01-19 09:27:03 +00:00
# Checkout an older commit
2017-11-22 09:55:50 +00:00
function gco_date() {
git checkout `git rev-list -n 1 --before="$1" master`
}
2012-09-22 00:30:00 +00:00
2019-02-28 05:20:17 +00:00
function make_aoc() {
pdftk $1 cat 1 output 1-$1
pdftk 1-$1 aoc.pdf cat output aoc-$1
}
2012-09-22 00:30:00 +00:00
COMP_WORDBREAKS=${COMP_WORDBREAKS/=/}
COMP_WORDBREAKS=${COMP_WORDBREAKS/@/}
export COMP_WORDBREAKS
# autoload -U compinit
# compinit
export BLOCKSIZE=K
# export CDPATH=.:~:~/src:/etc
# export DISPLAY=:79
2021-03-16 05:52:02 +00:00
export EDITOR='vim'
2021-03-16 06:39:06 +00:00
export GREP_OPTIONS='-D skip --binary-files=without-match --ignore-case'
2017-12-08 18:27:16 +00:00
# put list of remote hosts in ~/.hosts ...
export HOSTFILE=$HOME/.hosts
2012-09-22 00:30:00 +00:00
# export IGNOREEOF=1 # prevent CTRL-D from immediately logging out
# export INPUTRC=/etc/inputrc # it's possible that this will make bash find my delete key (and everything else)((but i don't think it did))
# export INPUTRC=$HOME/.inputrc # type in whatever and press Page Up key and bash automatically fetches last command that starts with whatever and completes the command for you (requires '$HOME/.inputrc' with these lines: #Page up/page down && "\e[5~": history-search-backward && "\e[6~": history-search-forward)
2018-04-16 17:46:05 +00:00
export LC_COLLATE="en_US.utf8" # change sorting methods [a-Z] instead of [A-Z]
2018-05-02 15:22:54 +00:00
export LESSCHARSET="UTF-8"
export LESS='-i -n -w -z-4 -g -e -M -X -F -Q -R -P%t?f%f \'
2012-09-22 00:30:00 +00:00
# export LESSOPEN="|lesspipe.sh %s"; export LESSOPEN
export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-' # use this if lesspipe.sh exists
# export LESS_TERMCAP_mb=$'\E[01;31m' # less colors for Man pages # begin blinking
2018-05-02 15:22:54 +00:00
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # less colors for Man pages # begin bold
export LESS_TERMCAP_me=$'\E[0m' # less colors for Man pages # end mode
export LESS_TERMCAP_se=$'\E[0m' # less colors for Man pages # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m' # less colors for Man pages # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # less colors for Man pages # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # less colors for Man pages # begin underline
2012-09-22 00:30:00 +00:00
# export MY_PROXY='http://YOUR_USERNAME:YOUR_PASSWORD@PROXY_IP:PROXY_PORT/'
# export OOO_FORCE_DESKTOP=gnome # openoffice preferences
export PAGER='less -e'
# export PILOTRATE=57600 # make pilot-xfer go faster than 9600
export TERM='xterm'
export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n'
2021-03-16 06:39:06 +00:00
2012-09-22 00:30:00 +00:00
# ${file%\.[^.]*} # to remove filename extensions in bash
2021-03-16 06:39:06 +00:00
# Disallow messages from other users
mesg n
# causes output from background processes to be output right away, not on wait for next primary prompt
set -b
set bell-style visible # I hate noise
set completion-ignore-case on # complete things that have been typed in the wrong case
2012-09-22 00:30:00 +00:00
# set -o ignoreeof # can't c-d out of shell
2021-03-16 06:39:06 +00:00
# notify when jobs running in background terminate
set -o notify
2012-09-22 00:30:00 +00:00
# set -o nounset # attempt to use undefined variable outputs error message and forces exit (messes up completion if enabled)
# set +o nounset # otherwise some completions will fail
#setopt autopushd pushdminus pushdsilent pushdtohome
# setopt correct
# setopt extendedglob
# setopt hist_verify # verify when using !
# setopt nocheckjobs # don't complain about background jobs on e
# setopt nohup # don't kill bg jobs when tty quits
# setopt printexitvalue # print exit value from jobs
# setopt share_history
# set -o xtrace # useful for debuging
# setterm -blength 0 # set the bell duration in milliseconds (silence the beeps)
# set visible-stats on # when listing possible file completions, put / after directory names and * after programs
shopt -s cdable_vars # set the bash option so that no '$' is required (disallow write access to terminal)
shopt -s cdspell # this will correct minor spelling errors in a cd command
shopt -s checkhash
shopt -s checkwinsize # update windows size on command
shopt -s cmdhist # save multi-line commands in history as single line
2017-12-30 06:00:34 +00:00
shopt -s dotglob # files beginning with . to be returned in the results of path-name expansion
2012-09-22 00:30:00 +00:00
# shopt -s expand aliases # expand aliases
shopt -s extglob # necessary for bash completion (programmable completion)
2017-12-30 06:00:34 +00:00
shopt -s globstar # enables the ** globbing operator
2012-09-22 00:30:00 +00:00
shopt -s histappend histreedit histverify
shopt -s hostcomplete # attempt hostname expansion when @ is at the beginning of a word
# shopt -s huponexit
#shopt -s mailwarn # keep an eye on the mail file (access time)
# shopt -s nocaseglob cdspell histappend
shopt -s nocaseglob # pathname expansion will be treated as case-insensitive (auto-corrects the case)
shopt -s no_empty_cmd_completion # no empty completion (bash>=2.04 only)
# shopt -s nullglob dotglob
shopt -s sourcepath
# shopt -u cmdhist # do not treat multiple line commands as a single entry
2017-12-30 06:00:34 +00:00
shopt -u force_fignore # expand to complete an ignored word, if no other words match.
2012-09-22 00:30:00 +00:00
# shopt -u mailwarn
# shopt -u sourcepath
# stty -ixon # disable XON/XOFF flow control (^s/^q)
stty start undef
stty stop undef
2017-12-30 06:00:34 +00:00
stty stop '' # use C-s to search forward through history (do not block output)
ulimit -c unlimited # let me have core dumps
# ulimit -S -c 0 # (core file size) don't want any coredumps
2012-09-22 00:30:00 +00:00
# ulimit -S -f 1024 # open files
# ulimit -S -s 8192 # stack size
# ulimit -S -u 256 # max user processes
# umask 007 # all files created 660, dirs 770
# umask 022 # makes new files have permissions: rwxr-xr-x
# umask 077 # after everything is installed, uncomment this and the mkdir alias below ((base 8) 777 & ~077 = 700 = u=rwx,g=,o=)
#unset MAILCHECK # don't want my shell to warn me of incoming mail
# unsetopt bgnice # don't nice bg command
2021-03-16 06:39:06 +00:00
# To create a ZIP archive of a file or folder
2012-09-22 00:30:00 +00:00
function zipf() { zip -r "$1".zip "$1" ; }
2021-01-19 09:27:03 +00:00
# Custom Functions For adding and fetching covers from a pdf
2012-09-22 00:30:00 +00:00
function addcover() { convert "$2" /tmp/cover.pdf; pdftk /tmp/cover.pdf "$1" cat output /tmp/final.pdf;mv /tmp/final.pdf "$1"; }
function getcover() { pdftk "$1" cat 1 output /tmp/cover.pdf; convert /tmp/cover.pdf cover.jpg;}
2021-03-16 06:39:06 +00:00
#######################
# Directory shortcuts #
#######################
2012-09-22 00:30:00 +00:00
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
alias gitci='git commit -a -m'
alias la_='ls -Al' # show hidden files
alias l?='cat ~/technical/tips/ls'
alias lc='ls -ltcr' # sort by and show change time, most recent last
alias ldir='ls -lhA |grep ^d'
alias ld='ls -ltr' # sort by date
alias lfiles='ls -lhA |grep ^-'
alias lf="ls -Alh --color | awk '{k=0;for(i=0;i<=8;i++)k+=((substr(\$1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(\" %0o \",k);print}'" # full ls with octal+symbolic permissions
alias lgg='ls --color=always | grep --color=always -i' # quick case-insenstive partial filename search
alias lh='ls -Al' # show hidden files
alias lh='ls -lAtrh' # sort by date and human readable
alias libpath='echo -e ${LD_LIBRARY_PATH//:/\\n}'
alias li='ls -ai1|sort' # sort by index number
alias linecount='wc -l $1' # count number of lines in text file
alias lk='ls -lSr' # sort by size
alias llllll='ls -FlaXo --color=auto' # sort the extensions alphabetically; good for winfiles
alias lllll='ls -Fla --full-time -o -Q --color=auto' # whatever
alias llll='ls -laS --color=auto' # sort by size
alias lll='ls -Falot --color=auto' # sort by mod time
alias ll_='ls -l' # long listing
alias l.='ls -d .[[:alnum:]]* 2> /dev/null || echo "No hidden file here..."' # list only hidden files
alias l='ls -hF --color' # quick listing
alias lm_='ls -al |more' # pipe through 'more'
alias ln='ln -s'
alias lr='ls -lR' # recursice ls
alias lrt='ls -lart' # list files with last modified at the end
alias lsam='ls -am' # List files horizontally
alias lsdd='ls -latr' # sort by date
alias lsd='ls -l | grep "^d"' # list only directories
alias lsize='ls --sort=size -lhr' # list by size
alias lsl='ls -lah' # long list, human-readable
alias ls='ls -hF --color' # add colors for filetype recognition
alias lsnew='ls -Alh --color=auto --time-style=+%D | grep `date +%D`'
alias lss='ls -shaxSr' # sort by size
alias lsss='ls -lrt | grep $1' # to see something coming into ls output: lss
alias lsx='ls -ax' # sort right to left rather then in columns
alias lt_='ls -alt|head -20' # 20, all, long listing, modification time
alias lt='ls -ltr' # sort by date, most recent last
alias lu='ls -ltur' # sort by and show access time, most recent last
alias lx='ls -lXB' # sort by extension
2015-07-16 13:50:37 +00:00
alias sss='sudo systemctl start'
2019-04-22 05:05:19 +00:00
alias sse='sudo systemctl enable'
alias ssd='sudo systemctl disable'
2018-04-26 10:30:01 +00:00
alias ssS='sudo systemctl stop'
2018-03-02 14:13:18 +00:00
alias ssh="cat ~/.ssh/config.d/p* > ~/.ssh/config; ssh"
2015-07-16 13:50:37 +00:00
alias ssr='sudo systemctl restart'
2015-08-25 16:53:07 +00:00
alias cda='composer dump-autoload'
2013-06-17 06:09:12 +00:00
2021-03-16 06:39:06 +00:00
#### autojump using z
2019-12-16 19:58:43 +00:00
alias z='j' # cd, same functionality as j in autojump
source /etc/profile.d/autojump.bash
2013-06-17 06:09:12 +00:00
2021-03-16 06:39:06 +00:00
# Docker
2018-05-02 15:22:54 +00:00
# docker run image
alias dri='docker run --volume /home/nemo/tmp:/data --tty --rm --interactive --entrypoint /bin/sh '
2021-03-16 06:39:06 +00:00
# Better caching (among other things)
# https://github.com/moby/moby/issues/15717
2020-06-15 13:51:26 +00:00
export DOCKER_BUILDKIT=1
2021-03-16 06:39:06 +00:00
2018-12-17 18:29:30 +00:00
# docker run image, but with current directory mounted as /current
# Do not run this on untrusted images
alias dri_cwd='docker run --volume `pwd`:/current --volume /home/nemo/tmp:/data --tty --rm --interactive --entrypoint /bin/sh '
2021-03-16 06:39:06 +00:00
# container-top
alias ctop='docker run --name ctop -it --rm -v /var/run/docker.sock:/var/run/docker.sock:ro quay.io/vektorlab/ctop '
2021-03-16 06:39:06 +00:00
# Run hadolint
2018-06-22 13:22:55 +00:00
alias dockerlint='LC_ALL=C hadolint'
2013-08-16 08:11:31 +00:00
2021-03-16 06:39:06 +00:00
# https://github.com/uber/makisu
function makisu_build() {
makisu_version=${MAKISU_VERSION:-v0.1.10}
cd ${@: -1}
docker run -i --rm --net host \
-v /var/run/docker.sock:/docker.sock \
-e DOCKER_HOST=unix:///docker.sock \
-v $(pwd):/makisu-context \
-v /tmp/makisu-storage:/makisu-storage \
gcr.io/makisu-project/makisu:$makisu_version build \
--commit=explicit \
--modifyfs=true \
--load \
${@:1:${#@}-1} /makisu-context
cd -
}
# Terraform
export TF_PLUGIN_CACHE_DIR="$HOME/.terraform.d/plugin-cache"
2019-01-24 20:10:35 +00:00
alias t=terraform
alias tp='terraform plan'
alias tpt='terraform plan --target '
alias ta='terraform apply'
alias tat='terraform apply --target '
alias tfa='terraform apply --auto-approve'
alias tfat='terraform apply --auto-approve --target '
2019-04-09 20:54:15 +00:00
alias tfit='terraform init'
2019-01-24 20:10:35 +00:00
##### History Shenanigans
2018-03-02 14:13:18 +00:00
export HISTCONTROL=ignorespace:ignoredups:erasedups # for 'ignoreboth': ignore duplicates and /^\s/
export HISTFILE='/home/nemo/.bash_history'
# export HISTFILESIZE=10000 # increase or decrease the size of the history to '10,000'
# export HISTFILESIZE=${HISTSIZE} # bash will remember 'N' commands
2017-12-08 18:27:16 +00:00
export HISTIGNORE='&:bg:fg:ll:h'
export HISTIGNORE='${HISTIGNORE:+$HISTIGNORE:}la:ll:lah:lat:;a:-:fg:bg:j:sync:esu:rma:rmp:fol:pfol'
export HISTIGNORE="&:ls:ll:la:l.:pwd:exit:clear"
export HISTIGNORE='pwd:cd:ls:ls -l:' # ignore commands given
#export HISTSIZE=10000 # increase or decrease the size of the history to '10,000'
2017-12-08 18:27:16 +00:00
export HISTTIMEFORMAT='| %d/%m/%y %T | ' # make 'History' Show The Date For Each Command
# export HISTTIMEFORMAT='%F %T ' # adds date and time to history
#export HISTTIMEFORMAT='%H:%M > '
# export HISTTIMEFORMAT='%s' # the beloved Second of Our Linux
# export HISTTIMEFORMAT='%Y-%b-%d::%Hh:%Mm:%Ss '
#export HISTTIMEFORMAT='%Y-%m-%d_%H:%M:%S_%a ' # makes history display in YYYY-MM-DD_HH:MM:SS_3CharWeekdaySpaceSpace format
2017-12-08 18:27:16 +00:00
unset HISTFILESIZE # infinite History
unset HISTSIZE # infinite History
# append to the history file, don't overwrite it
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000000
HISTFILESIZE=1000000
shopt -s histappend
2018-12-18 06:55:53 +00:00
# Don't use this for sensitive files
transfer() { if [ $# -eq 0 ]; then echo -e "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 --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile; rm -f $tmpfile; }
export JAVA_HOME=/usr/lib/jvm/default-runtime
2015-06-14 19:25:31 +00:00
# added by travis gem
[ -f /home/nemo/.travis/travis.sh ] && source /home/nemo/.travis/travis.sh
#PERL_MB_OPT="--install_base \"/home/nemo/perl5\""; export PERL_MB_OPT;
#PERL_MM_OPT="INSTALL_BASE=/home/nemo/perl5"; export PERL_MM_OPT;
#eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
2017-12-30 06:00:34 +00:00
# Manage multiple Git identities
2015-06-22 07:42:20 +00:00
# karn https://github.com/prydonius/karn
2019-01-24 20:10:35 +00:00
if command -v karn > /dev/null; then eval "$(karn init)"; fi
2015-06-22 07:42:20 +00:00
# Disable beeps
2015-07-24 13:49:35 +00:00
xset -b
2015-06-14 19:25:31 +00:00
# function make-completion-wrapper () {
# local function_name="$2"
# local arg_count=$(($#-3))
# local comp_function_name="$1"
# shift 2
# local function="
# function $function_name {
# ((COMP_CWORD+=$arg_count))
# COMP_WORDS=( "$@" \${COMP_WORDS[@]:1} )
# "$comp_function_name"
# return 0
# }"
# eval "$function"
# echo $function_name
# echo "$function"
# }
2016-08-16 11:33:01 +00:00
# http://boredzo.org/blog/archives/2016-08-15/colorized-man-pages-understood-and-customized
# colorized man pages
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LC_ALL=C \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
MANWIDTH=$(expr $COLUMNS - 4) \
man "$@"
}
function mkcd() {
2021-03-16 06:39:06 +00:00
mkdir --parents "$1"
cd "$1"
}
2019-12-31 15:15:53 +00:00
# To allow global package installations for the current user
PATH="$HOME/.node_modules/bin:$PATH"
export npm_config_prefix=~/.node_modules
2019-01-28 07:31:23 +00:00
# Stolen from @ThatHarmanSingh
function sprint() {
2021-08-24 09:14:39 +00:00
# Set time format to unix so we can subtract
HISTTIMEFORMAT='%s ' history |
2019-01-28 07:31:23 +00:00
# History returns way more than needed
tail -n 4000 |
2019-01-28 07:31:23 +00:00
# Grep for git commits (after timestamps)
grep -E '^\d+\s+\d+\s+gc' |
2019-01-28 07:31:23 +00:00
# Max 15 days ago
awk -v now=$(date +%s) '(now - $2) < 15*24*60*60' |
2019-01-28 07:31:23 +00:00
# Cut out the timestamps for uniq check
cut -d ' ' -f 4- |
# To handle multiple commit-pull-reset-commit cycles
uniq
2019-02-10 06:35:38 +00:00
}
# https://starship.rs/advanced-config/#change-window-title
function starship_set_win_title(){
echo -ne "\033]0; $PWD \007"
}
starship_precmd_user_func="starship_set_win_title"
eval "$(starship init bash)"
2021-02-26 08:31:52 +00:00
[ -s "/usr/share/scm_breeze/scm_breeze.sh" ] && source "/usr/share/scm_breeze/scm_breeze.sh"
2021-06-08 14:22:11 +00:00
function ytdl.album() {
cd $(mktemp -d)
2021-06-23 13:28:23 +00:00
youtube-dl --quiet -f "bestaudio[ext=m4a]" --output "audio.m4a" "$1"
2021-06-08 14:22:11 +00:00
youtube-cue --audio-file "audio.m4a" "$1" tracks.cue
m4acut -C tracks.cue "audio.m4a" && \
trash audio.m4a && \
beet import -map .
2021-06-23 13:28:23 +00:00
}
function gaanadl.album() {
cd $(mktemp -d)
2021-08-24 09:14:39 +00:00
youtube-dl --rm-cache-dir --no-cache-dir --quiet --autonumber-start 1 --add-metadata -o "%(autonumber)d - %(title)s.m4a" "$1"
2021-06-23 13:28:23 +00:00
beet import -map .
cd -
2022-01-16 18:45:34 +00:00
}
PATH="/home/nemo/perl5/bin${PATH:+:${PATH}}"; export PATH;
PERL5LIB="/home/nemo/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/home/nemo/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/home/nemo/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/home/nemo/perl5"; export PERL_MM_OPT;