mirror of
https://gitea.blesmrt.net/mikaela/shell-things.git
synced 2024-11-25 20:59:23 +01:00
Aminda Suomalainen
8acc9b391b
Apparently while Fedora does magick the aliases up from somewhere, Kali will complain about no such hassh table element
960 lines
32 KiB
Bash
Executable File
960 lines
32 KiB
Bash
Executable File
#!/usr/bin/env zsh
|
||
|
||
# European/standardizedish English for root
|
||
if [[ "$(id -u)" == "0" ]]; then
|
||
unset LC_ALL
|
||
unset LANGUAGE
|
||
export LANG="en_DK.UTF-8"
|
||
export LC_CTYPE="en_DK.UTF-8"
|
||
export LC_NUMERIC="en_DK.UTF-8"
|
||
export LC_TIME="en_DK.UTF-8"
|
||
export LC_COLLATE="en_DK.UTF-8"
|
||
export LC_MONETARY="en_DK.UTF-8"
|
||
export LC_MESSAGES="en_DK.UTF-8"
|
||
export LC_PAPER="en_DK.UTF-8"
|
||
export LC_NAME="en_DK.UTF-8"
|
||
export LC_ADDRESS="en_DK.UTF-8"
|
||
export LC_TELEPHONE="en_DK.UTF-8"
|
||
export LC_MEASUREMENT="en_DK.UTF-8"
|
||
export LC_IDENTIFICATION="en_DK.UTF-8"
|
||
fi
|
||
|
||
# TOC
|
||
# Defaults etc... M0TZLS
|
||
# Environment 7RS56S
|
||
# Aliases RJ706I
|
||
# Functions ZGC5QQ
|
||
|
||
# Kind of my welcome screen when I open a terminal?
|
||
# Existence of lsb_release implies both being on Linux and me having touched
|
||
# the system, so I can do away with a lot of checks for Darwin
|
||
if hash lsb_release 2> /dev/null; then
|
||
(
|
||
export LC_ALL="en_DK.UTF-8"
|
||
hostname --all-fqdns &
|
||
hostname --all-ip-addresses
|
||
printf "\n"
|
||
printf "$(uptime --pretty)\t$(uptime)\n"
|
||
printf "\nPresent:\n"
|
||
if hash who 2> /dev/null; then
|
||
who --heading --mesg --users
|
||
elif hash last 2> /dev/null; then
|
||
last --hostlast --present $(date +%R) --fullnames --system --time-format notime
|
||
fi
|
||
printf "\n"
|
||
df / $HOME --human-readable --output=source,fstype,size,used,avail,pcent | uniq
|
||
unset LC_ALL
|
||
)
|
||
|
||
# Only print motivational phrases if username is aminda or mikaela
|
||
if [[ $(whoami) == aminda ]] || [[ $(whoami) == mikaela ]]; then
|
||
(
|
||
printf "\n"
|
||
# Tavun OM värähtely poistaa ylpeyttä, MA kateutta, NI takertumista. PE leikkaa tietämättömyyden läpi, ME hälventää ahneuden ja rintakehässä värähtelevä HUNG muuntaa vihan.
|
||
# Kuinka asiat ovat (s. 74-75) - Lama Ole Nydahl
|
||
printf "\tAferoj emas funkcii sin mem... \t OM MANI PEME HUNG...\n"
|
||
printf "\tAlways remember the existence of spotlight effect...\n"
|
||
#(printf "\u26A7\ufe0e Aferoj emas funkcii sin mem.\n\tFaru jogon, sentu, ne provu perfektecon.\n\t\tDancu kiel neniu rigardas, kvankam estu vidita kaj aŭdata.\nOM MANI PEME HUNG\n")
|
||
#(printf "\u26A7\ufe0e Any movement at any time is better than nothing.\n")
|
||
#(printf "\u2744\ufe0e Take the cold showers, hot ones are a disservice. And walk in cold, which is no excuse just like rain.\n\tOtherwise there will be dry skin and the vagus nerve will be upset leading to anxiety, depression and poor mental health.\n\t\tBesides the environment thanks.\n")
|
||
# Tempus Finis - Takeharu Ishimoto
|
||
#(printf "\u1f54a\ufe0e \tFine fortasse nihil est vobis dire\n\tFine fortasse nihil est vobis Lucrari\n\tFine fortasse nihil est tamen\n")
|
||
#(printf "\u26A7\ufe0e Your adventure begins in the dead of night.\n\u26A7\ufe0e Your road won't be easy, but a rising sun awaits your journey's end.\n\n")
|
||
#(printf "\u26A7\ufe0e The darker than black is, the brighter the moon is\n")
|
||
#(printf "\u26A7\ufe0e Agoraphobia/social anxiety advice: \n\tAct like you belong! Like you own the place, but keep everyone comfortable! Remember the Spotlight Effect!\n \t\tMaybe even wear hi-viz so you really belong anywhere \U1F61D \n\t\t\tAnd as always, fake it till you make it!\n")
|
||
# (printf "\n\u26A7\ufe0e\tThat's what I am, that's what I'll always be\n\u26A7\ufe0e\tI don't wanna be silent 'cause this is my destiny\n\u26A7\ufe0e\tThat's what I was, that's what feels good to me\n\u26A7\ufe0e\tAnd nothing will change me, that's what I'm meant to be.\n\u26A7\ufe0e\t\t—Conchita Wurst: That's What I Am\n\n")
|
||
#(printf "https://en.m.wikipedia.org/wiki/First_they_came_...#Text\n")
|
||
printf "\tMay your heart be your guiding key ;)"
|
||
printf "\n"
|
||
)
|
||
elif [[ "$(id -u)" == "0" ]]; then
|
||
# This comes from Charybdis IRCd
|
||
(printf "\nWe would like to take this moment to remind you that we accept\nabsolutely no liability for the insanity you're about to endure.\n\n")
|
||
# And this from sudo + the general advice for auditability
|
||
(printf "We trust you have received the usual lecture from the local System\nAdministrator. It usually boils down to these three things:\n\n\t#1) Respect the privacy of others.\n\t#2) Think before you type.\n\t#3) With great power comes great responsibility.\n\nAdditionally you shouldn't be logging in as root directly.\n\n")
|
||
fi
|
||
fi
|
||
|
||
##### Defaults etc... M0TZLS #####
|
||
|
||
# This is based on zshrc which came with Debian (Third option in wizard for new users.)
|
||
|
||
# Save history
|
||
export HISTSIZE=99999
|
||
export SAVEHIST=$HISTSIZE
|
||
setopt hist_ignore_all_dups
|
||
export HISTFILE=~/.zsh_history
|
||
setopt INC_APPEND_HISTORY
|
||
setopt SHARE_HISTORY
|
||
|
||
# Set up the prompt
|
||
autoload -Uz promptinit
|
||
|
||
# Green for normal user and red for root
|
||
promptinit
|
||
|
||
if [ $USER = "root" ]; then
|
||
prompt elite2 red
|
||
else
|
||
prompt elite2 green
|
||
fi
|
||
|
||
# Newline before new prompt
|
||
precmd() {
|
||
precmd() {
|
||
printf "\n"
|
||
}
|
||
}
|
||
|
||
# Use emacs keybindings even if our EDITOR is set to vi
|
||
bindkey -e
|
||
|
||
# Use modern completion system
|
||
autoload -Uz compinit
|
||
compinit
|
||
|
||
zstyle ':completion:*' auto-description 'specify: %d'
|
||
zstyle ':completion:*' completer _expand _complete _correct _approximate
|
||
zstyle ':completion:*' format 'Completing %d'
|
||
zstyle ':completion:*' group-name ''
|
||
zstyle ':completion:*' menu select=2
|
||
#zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
|
||
zstyle ':completion:*' list-colors ''
|
||
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
|
||
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
|
||
zstyle ':completion:*' menu select=long
|
||
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
|
||
zstyle ':completion:*' use-compctl false
|
||
zstyle ':completion:*' verbose true
|
||
|
||
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
|
||
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
|
||
|
||
if hash dircolors 2> /dev/null; then
|
||
eval $(dircolors --bourne-shell)
|
||
#alias ls='ls --color=auto'
|
||
#alias dir='dir --color=auto'
|
||
#alias vdir='vdir --color=auto'
|
||
fi
|
||
|
||
##### Environment 7RS56S #####
|
||
# Environment should be placed to .environment or .zsh_environment (or .zshenv).
|
||
|
||
# Source before mentioned locations if they exist.
|
||
|
||
# .environment
|
||
if [ -f ~/.environment ]; then
|
||
source ~/.environment
|
||
fi
|
||
|
||
# .zsh_environment
|
||
if [ -f ~/.zsh_environment ]; then
|
||
source ~/.zsh_environment
|
||
fi
|
||
|
||
# .zshenv (Yes, I know that this is sourced by every zsh session even if this isn't here, but I just want to write it).
|
||
if [ -f ~/.zshenv ]; then
|
||
source ~/.zshenv
|
||
fi
|
||
|
||
# Enable core files.
|
||
(ulimit -c unlimited &)
|
||
|
||
# More colours
|
||
if [[ $TERM == 'xterm' ]]; then
|
||
export TERM=xterm-256color
|
||
fi
|
||
|
||
if [[ $TERM == 'screen' ]]; then
|
||
export TERM=screen-256color
|
||
fi
|
||
|
||
# Sets the default editor.
|
||
#export EDITOR=nvim # MIKAELA_GREP MIKAELA_GREP_ENVIRONMENT
|
||
|
||
# Set TZ to local timezone for sending over SSH
|
||
TZ=$(date +%Z)
|
||
|
||
# Sets PATH. To add another path, add :</path/to/new/path> to string below.
|
||
PATH=$HOME/.local/bin:$HOME/bin:$HOME/go/bin:$HOME/.local/share/flatpak/exports/bin:/var/lib/flatpak/exports/bin:/usr/local/bin:/usr/local/sbin:/usr/local/games:/snap/bin:/usr/bin:/usr/sbin:/usr/games:/bin:/sbin:/games:$PATH
|
||
|
||
# Colours to less
|
||
# Copied from https://nion.modprobe.de/blog/archives/572-less-colors-for-man-pages.html
|
||
export LESS_TERMCAP_mb=$'\E[01;31m'
|
||
export LESS_TERMCAP_md=$'\E[01;31m'
|
||
export LESS_TERMCAP_me=$'\E[0m'
|
||
export LESS_TERMCAP_se=$'\E[0m'
|
||
export LESS_TERMCAP_so=$'\E[01;44;33m'
|
||
export LESS_TERMCAP_ue=$'\E[0m'
|
||
export LESS_TERMCAP_us=$'\E[01;32m'
|
||
|
||
# if gpg[-agent] has sshcontrol file, use it as ssh-agent. sshcontrol should
|
||
# include the authentication subkey keygrip from
|
||
# `gpg --with-keygrip --list-keys`
|
||
# Assumption: there is not going to be a sshcontrol file if `gpgconf` is not
|
||
# installed or `sshcontrol` is trivial to remove.
|
||
if [ -f ~/.gnupg/sshcontrol ]; then
|
||
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
|
||
gpgconf --launch gpg-agent
|
||
gpg-connect-agent updatestartuptty /bye > /dev/null 2>&1
|
||
# otherwise use the normal ssh-agent
|
||
else
|
||
# if the output is going to /dev/null, it's non/existence doesn't matter
|
||
(ssh-agent -a /tmp/$USER.sshagent > /dev/null 2>&1)
|
||
export SSH_AUTH_SOCK=/tmp/$USER.sshagent
|
||
fi
|
||
|
||
# If we are on Linux, enable apt progress bar and colours
|
||
#if [[ $USER = "root" ]]; then
|
||
# mkdir -p /etc/apt/apt.conf.d/
|
||
# echo 'Dpkg::Progress-Fancy "1";' > /etc/apt/apt.conf.d/99progressbar
|
||
# echo 'APT::Color "1";' > /etc/apt/apt.conf.d/99color
|
||
#fi
|
||
|
||
# OS X ls colours (copied from https://apple.stackexchange.com/questions/33677/
|
||
#export CLICOLOR=1
|
||
#export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
|
||
|
||
# znc uses this variable for figuring out hostname
|
||
#export HOSTNAME=$(hostname --fqdn)
|
||
|
||
# Ensure not leaking queries to upstream nameservers (resolv.conf)
|
||
export LOCALDOMAIN=.
|
||
# Secureish resolv.conf options (except trust-ad, but systemd also sets it
|
||
# regardless of whether DNSSEC=true or not.
|
||
export RES_OPTIONS="timeout:1 attempts:5 rotate edns0 trust-ad"
|
||
|
||
# https://github.com/go-nv/goenv
|
||
if [ -f /home/linuxbrew/.linuxbrew/opt/goenv/bin/goenv ]; then
|
||
eval "$(/home/linuxbrew/.linuxbrew/opt/goenv/bin/goenv init -)" > /dev/null 2>&1
|
||
PATH=/home/linuxbrew/.linuxbrew/opt/goenv/bin/shims:$PATH
|
||
elif [ -f ~/.goenv/bin/goenv ]; then
|
||
eval "$(~/.goenv/bin/goenv init -)" > /dev/null 2>&1
|
||
fi
|
||
|
||
# https://github.com/nvm-sh/nvm
|
||
if [ -d /home/linuxbrew/.linuxbrew/opt/nvm ]; then
|
||
mkdir -p /home/linuxbrew/.nvm
|
||
export NVM_DIR=/home/linuxbrew/.nvm
|
||
. /home/linuxbrew/.linuxbrew/opt/nvm/nvm.sh
|
||
elif [ -d ~/.nvm ]; then
|
||
. ~/.nvm/nvm.sh
|
||
. ~/.nvm/bash_completion
|
||
fi
|
||
|
||
# https://github.com/rbenv/rbenv
|
||
if [ -f /home/linuxbrew/.linuxbrew/opt/rbenv/bin/rbenv ]; then
|
||
eval "$(/home/linuxbrew/.linuxbrew/opt/rbenv/bin/rbenv init -)"
|
||
PATH=/home/linuxbrew/.linuxbrew/opt/rbenv/bin/shims:$PATH
|
||
|
||
# No OpenSSL? Remember (and substitute the x, y and z)!:
|
||
# rbenv install -- --with-openssl-dir=/home/linuxbrew/.linuxbrew/Cellar/openssl@x/x.y.z/
|
||
elif [ -f ~/.rbenv/bin/rbenv ]; then
|
||
eval "$(~/.rbenv/bin/rbenv init -)"
|
||
# Remember! And verify it before running!
|
||
# git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
|
||
fi
|
||
|
||
# Add RubyGems to PATH
|
||
if hash ruby 2> /dev/null; then
|
||
PATH="$(ruby -e 'print Gem.user_dir')/bin:$PATH"
|
||
fi
|
||
|
||
# https://github.com/pyenv/pyenv
|
||
if [ -f /home/linuxbrew/.linuxbrew/opt/pyenv/bin/pyenv ]; then
|
||
eval "$(/home/linuxbrew/.linuxbrew/opt/pyenv/bin/pyenv init -)"
|
||
PATH=/home/linuxbrew/.linuxbrew/opt/pyenv/bin/shims:$PATH
|
||
elif [ -d ~/.pyenv/bin ]; then
|
||
eval "$(~/.pyenv/bin/pyenv init -)"
|
||
# Worth considering (and verifying before running)
|
||
# git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
|
||
# git clone https://github.com/pyenv/pyenv-virtualenvwrapper.git $(pyenv root)/plugins/pyenv-virtualenvwrapper
|
||
fi
|
||
|
||
# https://github.com/nodenv/nodenv
|
||
if [ -f /home/linuxbrew/.linuxbrew/opt/nodenv/bin/nodenv ]; then
|
||
eval "$(/home/linuxbrew/.linuxbrew/opt/nodenv/bin/nodenv init -)"
|
||
PATH=/home/linuxbrew/.linuxbrew/opt/nodenv/bin/shims:$PATH
|
||
elif [ -d ~/.nodenv/bin/nodenv ]; then
|
||
eval "$(~/.nodenv/bin/nodenv init -)"
|
||
# Remember! And verify it before running!
|
||
# git clone https://github.com/nodenv/node-build.git "$(nodenv root)"/plugins/node-build
|
||
fi
|
||
|
||
# https://github.com/Homebrew/brew
|
||
if [ -d /home/linuxbrew/.linuxbrew/bin ]; then
|
||
eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
|
||
fi
|
||
|
||
# Removes duplicates from $PATH. Copied from https://unix.stackexchange.com/a/14896
|
||
PATH=$(echo "$PATH" | awk -v RS=':' -v ORS=":" '!a[$1]++{if (NR > 1) printf ORS; printf $a[$1]}')
|
||
|
||
##### Aliases RJ706I #####
|
||
|
||
# To get sudo work with aliases. And workaround nvim/tmux crash.
|
||
alias sudo="\sudo --preserve-env=tmux"
|
||
|
||
# Moving between directories:
|
||
alias ..="cd .."
|
||
|
||
# Use htop instead of top if available
|
||
if hash htop 2> /dev/null; then
|
||
alias top="htop"
|
||
fi
|
||
|
||
# Add title to youtube-dl & make yle-dl Windows-friendly
|
||
alias youtube-dl="youtube-dl -o '%(title)s-%(id)s.%(ext)s'"
|
||
alias yle-dl="yle-dl --vfat"
|
||
|
||
# git specific. This is the command which I use when git asks me to commit something and says that I have modified files, even when I haven't.
|
||
alias gdrop="git stash && git stash drop"
|
||
|
||
# Show compilation date of WeeChat.
|
||
alias weechat-version="weechat --help|head -n2"
|
||
|
||
# NMAP specific. All nmap things should be run with sudo.
|
||
alias nmap-intense="nmap -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 "
|
||
alias nmap-intense-udp="sudo nmap -sS -sU -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 "
|
||
alias nmap-intense-all-tcp="nmap -p 1-65535 -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 "
|
||
alias nmap-intense-no-ping="nmap -T4 -A -v -PN "
|
||
alias nmap-ping="nmap -sP -PE -PA21,23,80,3389 "
|
||
alias nmap-quick="nmap -T4 -F "
|
||
alias nmap-quick-plus="sudo nmap -sV -T4 -O -F --version-light "
|
||
alias nmap-traceroute="sudo nmap -sP -PE -PS22,25,80 -PA21,23,80,3389 -PU -PO --traceroute "
|
||
alias nmap-regular="nmap "
|
||
alias nmap-comprehensive="sudo nmap -sS -sU -T4 -A -v -PE -PP -PS21,22,23,25,80,113,31339 -PA80,113,443,10042 -PO --script all "
|
||
# Little "safer" scan as connecting to only HTTP and HTTPS ports doesn't look so attacking. Copy-paste to .zsh_custom and remove" -p 80,443" if you want to scan all ports which nmap scans by default.
|
||
alias nmap-osscan="sudo nmap -p 80,443 -O -v --osscan-guess --fuzzy "
|
||
|
||
# Downloads folder over SSH. Usage: rdownload <host>:<remotefolder> <local_destination> | TIP: use ~/ssh/config to configure hosts.
|
||
alias rdownload="rsync -h --progress -avz "
|
||
alias rscp='rsync -h --progress -avz '
|
||
alias rscpr='rsync -h --progress -azvv '
|
||
|
||
# TMUX specific
|
||
alias tmux="tmux -2u"
|
||
alias attach="tmux attach-session"
|
||
alias detach="tmux detach"
|
||
|
||
# Supybot specifig. Why to write long command, if you can write short command?
|
||
alias supybot-config-reload="killall -HUP supybot "
|
||
alias supybot-owner-quit="killall -INT supybot "
|
||
# Translating plugins in Limnoria
|
||
alias supybot-generate-messages.pot="pygettext --docstrings config.py plugin.py"
|
||
alias supybot-generate-messages.pot-xgettext="xgettext --language=Python config.py plugin.py && mv -f messages.po messages.pot"
|
||
alias supybot-check-plugin-trans="sandbox/check_trans.py plugins/"
|
||
alias supybot-check-core-trans="sandbox/check_trans.py --core"
|
||
alias supybot-generate-messages.pot-mass="find . -type d -exec sh -c '(cd {} && pygettext --docstrings config.py plugin.py)' ';'"
|
||
|
||
# ZSH specific.
|
||
# I think that "theme" is more describing than "prompt".
|
||
alias theme="prompt "
|
||
|
||
## -- Start of aliases which are saved from Ubuntu default bashrc. --
|
||
|
||
#alias ls='ls --color=auto'
|
||
#alias dir='dir --color=auto'
|
||
#alias vdir='vdir --color=auto'
|
||
|
||
alias grep='grep --color=auto'
|
||
alias fgrep='fgrep -F --color=auto'
|
||
alias egrep='egrep -E --color=auto'
|
||
|
||
# Add an "alert" alias for long running commands. Use like so:
|
||
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$//'\'')"'
|
||
|
||
## -- End of aliases which are saved from Ubuntu default bashrc. --
|
||
|
||
# Enable colours for diff when in terminal
|
||
alias diff="diff --color=auto"
|
||
|
||
# SSHGuard specific
|
||
alias sshguard-show-bans="sshguard4-show-bans && sshguard6-show-bans"
|
||
alias sshguard4-show-bans="sudo iptables -L sshguard --line-numbers"
|
||
alias sshguard6-show-bans="sudo ip6tables -L sshguard --line-numbers"
|
||
# Enter ban number as arguement. You can see ban numbers with previous command.
|
||
alias sshguard4-unban="sudo iptables -D sshguard "
|
||
alias sshguard6-unban="sudo ip6tables -D sshguard "
|
||
alias sshguard-unban-all="sshguard4-unban-all && sshguard-6-unban-all"
|
||
alias sshguard4-unban-all="sudo iptables -F sshguard"
|
||
alias sshguard6-unban-all="sudo ip6tables -F sshguard"
|
||
|
||
# For locally rsync copying folder1 to folder2.
|
||
alias rsync-folder="rsync -h --progress -azvv "
|
||
|
||
# SSHGuard seems to prefer users to run this always when connecting with keys in ssh-agent...
|
||
|
||
# Use GPG2 instead of GPG!
|
||
if hash gpg2 2> /dev/null; then
|
||
alias gpg=gpg2
|
||
export KEYBASE_GPG=gpg2
|
||
fi
|
||
alias gpg-fix-tty='export GPG_TTY=$(tty)'
|
||
|
||
# Amount of keys in GPG keyring.
|
||
alias gpg-key-amount="gpg --list-keys|grep '^pub'|wc -l"
|
||
alias gpg-key-count="gpg --export -a|gpg --import"
|
||
|
||
# Current IPv4 and IPv6 addresses. Calls functions.
|
||
alias myip="myip4 && myip6"
|
||
|
||
# Update groups without logging out. Requires entering password. Source: https://blog.edwards-research.com/2010/10/linux-refresh-group-membership-without-logging-out/
|
||
alias refreshgroups="exec su -l $USER"
|
||
|
||
# Get public key lenght of (public) SSH key
|
||
alias ssh-pubkey-length="ssh-keygen -lf "
|
||
|
||
# MSDOS commands. MSDOS is after every alias line to get these lines easily by grepping.
|
||
alias cls=clear # MSDOS
|
||
alias help=man # MSDOS
|
||
alias ipconfig=ifconfig # MSDOS
|
||
alias copy=cp # MSDOS
|
||
alias move=mv # MSDOS
|
||
|
||
# List git committers of repository
|
||
alias git-committers="git shortlog -s"
|
||
alias git-changelog="git log --oneline --decorate"
|
||
alias git-changelog-color="git log --oneline --decorate --color"
|
||
|
||
# Line ending converting with flip
|
||
alias unixle="flip -ub "
|
||
alias msdosle="flip -mb "
|
||
|
||
# Archiving and extracting with tar
|
||
# This is tartar to avoid conflict with tar
|
||
alias tartar="tar cfv "
|
||
alias targz="tar cfvz "
|
||
alias tarbz2="tar cfvj "
|
||
# I have function ex so these are ex-* to avoid conflict.
|
||
# ex-tartar and ex-tar, because there is alias tartar and command tar
|
||
alias ex-tar="tar xfv "
|
||
alias ex-tartar="tar xfv "
|
||
alias ex-targz="tar xfvz "
|
||
alias ex-tarbz2="tar xfvj "
|
||
|
||
# systemd runlevels/targets
|
||
alias currenttargets="systemctl list-units --type=target"
|
||
alias telsystemd="systemctl isolate "
|
||
alias defaulttarget="systemctl enable "
|
||
|
||
# For getting timestamps in history
|
||
alias history="history -i "
|
||
|
||
# To have less handle ls colours
|
||
alias less="less -R "
|
||
|
||
# "su -" with/without sudo. Conflicts with SailfishOS, to learn to use sui
|
||
# instead.
|
||
if ! hash ssu 2> /dev/null; then
|
||
alias ssu="echo 'No.'"
|
||
fi
|
||
alias sui="sudo -i"
|
||
alias sudoi="sudo -i"
|
||
#alias suu="su -"
|
||
|
||
# Who command which I use with Conky
|
||
alias cwho="who -H -w -u"
|
||
|
||
# inxi - https://smxi.org/docs/inxi.htm
|
||
#alias inxi-install="mkdir -p ~/.local/bin && cd ~/.local/bin && \wget -Nc https://github.com/smxi/inxi/raw/master/inxi && \chmod -v +x inxi && cd"
|
||
#alias inxi-install-root="cd /usr/local/bin;\wget -Nc https://github.com/smxi/inxi/raw/master/inxi;\chmod -v +x inxi;./inxi -U;cd"
|
||
#alias inxi-update="inxi -U"
|
||
|
||
# FINEID to ssh-agent
|
||
alias fineid="ssh-add -s /usr/lib64/libcryptoki.so"
|
||
|
||
# OS X
|
||
# What is this?
|
||
#alias osx-server-caching-interface="serveradmin settings caching:Interface ="
|
||
alias osx-show-hidden-files="defaults write com.apple.finder AppleShowAllFiles"
|
||
# Workaround on unsupported devices?
|
||
alias osx-airdrop-listenallif="defaults write com.apple.NetworkBrowser BrowseAllInterfaces"
|
||
alias osx-set-updatecheck="defaults write /Library/Preferences/com.apple.SoftwareUpdate ScheduleFrequency"
|
||
|
||
# Resetting different desktop environments
|
||
# TODO: I imagine these are broken
|
||
#alias reset-gnome="rm -rf ~/.gnome ~/.gnome2 ~/.gconf ~/.gconfd ~/.metacity ~/.cache ~/.dbus ~/.dmrc ~/.mission-control ~/.thumbnails ~/.config/dconf/user ~/.compiz*"
|
||
#alias reset-unity="unity-tweak-tool --reset-unity"
|
||
#alias reset-kde="rm -rf ~/.kde4 ~/.kde"
|
||
#alias reset-lxpanel="rm -rf ~/.config/lxpanel;lxpanelctl restart"
|
||
#alias reset-xfce4="rm -rf ~/.config/xfce4"
|
||
#alias reset-matepanel="mate-panel --reset"
|
||
|
||
# Show information on PEM file.
|
||
alias peminfo="openssl x509 -text -in"
|
||
|
||
# tmux emergency attach
|
||
alias tmuxeattach="/proc/$(pgrep -o tmux)/exe attach"
|
||
|
||
# Reset configuration files on systems using apt
|
||
alias purgeconfig="apt-get install --reinstall -o DPkg::options::=--force-confask"
|
||
|
||
# Send command output to sprunge.us or ix.io `command|<sprungeus|ixio>`
|
||
alias sprungeus="curl -F 'sprunge=<-' https://sprunge.us"
|
||
alias ixio="curl -F 'f:1=<-' ix.io"
|
||
|
||
# Copy-paste mtr output more easily
|
||
alias mtrp4="mtr -rw4c 10"
|
||
alias mtrp6="mtr -rw6c 10"
|
||
|
||
# Simple HTTPd with Python.
|
||
alias python-httpd="python3 -m http.server"
|
||
|
||
# pip
|
||
alias pip="python3 -m pip"
|
||
alias pip3="python3 -m pip"
|
||
alias pypypip="pypy3 -m pip"
|
||
alias pypypip3="pypy3 -m pip"
|
||
alias pipx="python3 -m pipx"
|
||
alias pipx3="python3 -m pipx"
|
||
alias pypypipx="pypy3 -m pipx"
|
||
alias pypypipx3="pypy3 -m pipx"
|
||
|
||
# Python virtualenv/the new venv comparsion:
|
||
# https://virtualenv.pypa.io/en/latest/#virtualenv / python3-venv (Debian)
|
||
alias venv="python3 -m venv"
|
||
alias pypyvenv="pypy3 -m venv"
|
||
alias venvpypy=pypyvenv
|
||
|
||
# cp/mv using rsync. rcp appears to be link to scp in my system, so I can
|
||
# safely use this alias.
|
||
if hash rsync 2> /dev/null; then
|
||
alias rcp="rsync -a --progress"
|
||
alias rmv="rsync -a --progress --remove-source-files"
|
||
fi
|
||
|
||
# Clear apt list cache
|
||
alias clear-apt-list-cache="cd /var/lib/apt/lists && rm -f *|true && cd partial && rm -f *|true && cd"
|
||
|
||
# Accept all cookies with Lynx, makes browsing easier and
|
||
# every other browser does this too.
|
||
alias lynx="lynx -accept_all_cookies"
|
||
|
||
# Cat multiple files preserving filenames
|
||
# via https://stackoverflow.com/a/7816490
|
||
alias multicat='tail -n +1'
|
||
|
||
# Getting SSIDs and keys from connmann (Jolla)
|
||
alias connman-wlans='grep -E "Name|Passphrase" /var/lib/connman/wifi*/settings --no-filename'
|
||
|
||
# Turn input into lowercase and remove colons.
|
||
# Meant for SSL certificates (IRC))
|
||
alias lowernocolon="tr -d ':' | tr 'A-Z' 'a-z'"
|
||
|
||
# I don't want to reinstall exact same versions that I have
|
||
alias pacman="LANG=en pacman --needed"
|
||
#fi
|
||
|
||
# Sailfish Network status, via IRC
|
||
alias sailfish-nstatus='dbus-send --system --type=method_call --print-reply --dest=net.connman / net.connman.Manager.GetServices|less'
|
||
|
||
# apt build depedencies (without installing)
|
||
alias apt-builddep="apt-rdepends --build-depends --follow=DEPENDS"
|
||
|
||
# https://superuser.com/a/638033 - get embedded Windows product key
|
||
alias winkey="xxd /sys/firmware/acpi/tables/MSDM"
|
||
|
||
# Always exec startx/startsway/wayland/sway so Ctrl-Alt-Backspace won't lead to unlocked TTY.
|
||
#alias startsway="exec dbus-launch --exit-with-session sway --unsupported-gpu"
|
||
alias startsway="\exec startsway"
|
||
alias startplasma="\exec startplasma"
|
||
#alias startx="exec \startx"
|
||
alias startx=startsway
|
||
alias startwayland=startsway
|
||
alias startwl=startsway
|
||
|
||
# cat list of kernel detected vulnerabilities/states with filenames
|
||
alias linux-check-cpu-vulns="tail -n +1 /sys/devices/system/cpu/vulnerabilities/*"
|
||
|
||
# gpg web key directory lookup
|
||
alias wkdlookup="gpg --auto-key-locate nodefault,wkd --locate-keys"
|
||
# Debian key server, Tor not necessary due to dirmngr config
|
||
alias gpg-dkr-recv="gpg --keyserver hkps://keyring.debian.org --recv-keys"
|
||
# Ubuntu key server, Tor not necessary due to dirmngr config
|
||
alias gpg-uks="gpg --keyserver hkps://keyserver.ubuntu.com"
|
||
alias gpg-uks-recv="gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys"
|
||
# helpful for wkd
|
||
alias gpg-export-minimal-ascii="gpg --armor --export-options export-minimal --export"
|
||
alias gpg-export-minimal-binary="gpg --no-armor --export-options export-minimal --export"
|
||
|
||
# ports that are being listened to
|
||
alias netstat-listening-ports="netstat -plntu"
|
||
|
||
# mpv music & music shuffle
|
||
alias mpvm="mpv --no-video"
|
||
alias mpvms="mpv --no-video --shuffle"
|
||
|
||
# Compatibility with my i3 alsactl mess
|
||
if [ -f ~/.config/asound.state ]; then
|
||
alias alsactl="\alsactl -f ~/.config/asound.state"
|
||
fi
|
||
|
||
# More simple SSH file signing, ~/.ssh/signingkey.pub should be a symlink
|
||
alias ssh-sign-file="ssh-keygen -Y sign -f ~/.ssh/signingkey.pub -n file"
|
||
|
||
# Anywhere on Earth date, https://en.m.wikipedia.org/wiki/Anywhere_on_Earth
|
||
alias aoedate="TZ=Etc/GMT+12 date"
|
||
|
||
# verbosity to common actions
|
||
alias rm="\rm --verbose"
|
||
alias ln="\ln --verbose"
|
||
alias mkdir="\mkdir --verbose"
|
||
alias chattr="\chattr -V"
|
||
alias chmod="\chmod --verbose"
|
||
|
||
# https://github.com/nodejs/corepack/blob/v0.28.2/README.md#corepack-enable--name
|
||
if hash corepack 2> /dev/null; then
|
||
alias yarn="corepack yarn"
|
||
alias yarnpkg="corepack yarnpkg"
|
||
alias pnpm="corepack pnpm"
|
||
alias pnpx="corepack pnpx"
|
||
alias npm="corepack npm"
|
||
alias npx="corepack npx"
|
||
if ! hash prettier 2> /dev/null; then
|
||
alias prettier="corepack pnpx prettier --cache --ignore-unknown"
|
||
fi
|
||
else
|
||
echo "Information: corepack is not installed."
|
||
fi
|
||
|
||
# https://pnpm.io/installation#using-a-shorter-alias
|
||
alias pn="corepack pnpm"
|
||
|
||
# github-pages etc.
|
||
if hash bundle 2> /dev/null; then
|
||
alias jekyll="bundle exec jekyll"
|
||
fi
|
||
|
||
# Helpful tool for increasing permissions on Android, for me mainly unattended
|
||
# installations.
|
||
alias shizuku="adb shell sh /storage/emulated/0/Android/data/moe.shizuku.privileged.api/start.sh"
|
||
|
||
# journalctl commands I often seem to type by hand
|
||
alias journalf="journalctl --no-hostname --follow"
|
||
alias journalfu="journalctl --utc --no-hostname --follow"
|
||
alias journalb="journalctl --no-hostname --boot"
|
||
alias journalbu="journalctl --utc --no-hostname --boot"
|
||
|
||
# To complement my nordvpn-off wrapper
|
||
alias nordvpn-offf="sudo systemctl stop nordvpnd.service;sudo systemctl stop nordvpnd.socket"
|
||
alias nordvpn-off2=nordvpn-offf
|
||
|
||
# Allow custom aliases to be put in .aliases or .zsh_aliases .
|
||
|
||
# .aliases
|
||
if [ -f ~/.aliases ]; then
|
||
source ~/.aliases
|
||
fi
|
||
|
||
# .zsh_aliases
|
||
if [ -f ~/.zsh_aliases ]; then
|
||
source ~/.zsh_aliases
|
||
fi
|
||
|
||
##### Functions ZGC5QQ #####
|
||
|
||
# GEOIP lookup, improved from the ultimate bashrc https://goo.gl/qGK5j
|
||
function geoip() {
|
||
geoiplookup $1
|
||
geoiplookup6 $1
|
||
}
|
||
|
||
# TODO: Is it bash or zshrc?
|
||
# ex command. Copied from zshrc of bioterror ( https://ricecows.org/configs/zsh/.zshrc ). Original comment below:
|
||
## for unit193 ;)
|
||
## use command "ex" to extract any archive files.
|
||
## "ex package.zip" for example
|
||
function ex() {
|
||
if [ -f "$1" ]; then
|
||
case "$1" in
|
||
*.tar) tar xvf $1 ;;
|
||
*.tar.bz2 | *.tbz2) tar xjvf $1 ;;
|
||
*.tar.gz | *.tgz) tar xzvf $1 ;;
|
||
*.bz2) bunzip2 $1 ;;
|
||
*.rar) unrar x $1 ;;
|
||
*.gz) gunzip $1 ;;
|
||
*.zip) unzip $1 ;;
|
||
*.Z) uncompress $1 ;;
|
||
*.7z) 7z x $1 ;;
|
||
*.xz) tar xJvf $1 ;;
|
||
*.deb)
|
||
DIR=${1%%_*.deb}
|
||
ar xv $1
|
||
mkdir ${DIR}
|
||
tar -C ${DIR} -xzvf data.tar.gz
|
||
;;
|
||
*.rpm) rpm2cpio $1 | cpio -vid ;;
|
||
*)
|
||
echo ""${1}" cannot be extracted via extract()"
|
||
;;
|
||
esac
|
||
else
|
||
echo ""${1}" is not a valid file"
|
||
fi
|
||
}
|
||
|
||
# Given by nyuszika7h. Shortens GitHub URLs with git.io
|
||
function gitio() {
|
||
curl -s -i https://git.io -F "url=$1" | grep --color=never -P '^Location: ' | awk '{ print $2 }'
|
||
}
|
||
|
||
function mkcd() {
|
||
if [[ $# -gt 1 ]]; then
|
||
echo 'Warning: All directories will be created, but will change to first specified directory.' 1>&2
|
||
fi
|
||
mkdir -p "$*" && cd "$1"
|
||
}
|
||
|
||
function gribble-gpg-everify() {
|
||
# Set which command to use for gpg. You
|
||
# probably want to use gpg2 here.
|
||
local gpg=gpg2
|
||
|
||
echo -n 'Enter Bitcoin OTC URL: '
|
||
read REPLY
|
||
lynx -hiddenlinks=ignore -dump $REPLY > bitcoin_otc.txt.asc
|
||
$gpg --decrypt-file bitcoin_otc.txt.asc
|
||
echo -en '\e[1;32m;;everify '
|
||
cat bitcoin_otc.txt
|
||
echo -e '\e[0m'
|
||
rm -rf bitcoin_otc.txt bitcoin_otc.txt.asc
|
||
}
|
||
|
||
# This function will install/upgrade shell-things.
|
||
|
||
function shell-things {
|
||
|
||
export SHELL_THINGS_REPO=$HOME/.shell-things
|
||
|
||
# Check if ~/.shell-things exists and cd and pull.
|
||
if [ -d $SHELL_THINGS_REPO ]; then
|
||
echo "shell-things: $SHELL_THINGS_REPO exists, git pulling..."
|
||
echo ""
|
||
cd $SHELL_THINGS_REPO
|
||
git remote set-url origin https://gitea.blesmrt.net/Mikaela/shell-things.git
|
||
git fetch --all
|
||
git pull
|
||
git verify-commit HEAD || exit 1
|
||
sleep 10
|
||
echo ""
|
||
echo "shell-things: Installing/Upgrading..."
|
||
echo ""
|
||
# If it doesn't exist...
|
||
else
|
||
echo ""
|
||
echo "shell-things: $SHELL_THINGS_REPO doesn't exist, cloning..."
|
||
echo ""
|
||
git clone https://gitea.blesmrt.net/Mikaela/shell-things.git $SHELL_THINGS_REPO
|
||
cd $SHELL_THINGS_REPO
|
||
sleep 10
|
||
echo ""
|
||
echo "shell-things: Installing/Upgrading..."
|
||
echo ""
|
||
fi
|
||
|
||
# Installing...
|
||
bash -x ./install
|
||
echo ""
|
||
echo "shell-things: Installing finished."
|
||
echo ""
|
||
|
||
echo ""
|
||
echo "shell-things: Everything is now done :)"
|
||
echo ""
|
||
|
||
cd
|
||
|
||
}
|
||
|
||
# This function removes and regenerates ssh host keys.
|
||
|
||
#ssh-regen-host-keys () {
|
||
# rm /etc/ssh/ssh_host_*
|
||
# ssh-keygen -t rsa -N "" -f /etc/ssh/ssh_host_rsa_key
|
||
# ssh-keygen -t ed25519 -N "" -f /etc/ssh/ssh_host_ed25519_key
|
||
#}
|
||
|
||
# This function erases Master Boot Record from device
|
||
# Note: this is dangerous so this function will echo the command
|
||
# instad of running it!
|
||
#erase-mbr() {
|
||
# echo dd if=/dev/zero of=$1 bs=512 count=2
|
||
#}
|
||
|
||
# Use clang if installed. It seems interesting and this is probably good
|
||
# way to test it. This might not be a function, but I don't have any better
|
||
# place for this.
|
||
if hash clang 2> /dev/null; then
|
||
export CC=clang
|
||
export HOMEBREW_CC=clang
|
||
fi
|
||
|
||
if hash clang++ 2> /dev/null; then
|
||
export CXX=clang++
|
||
fi
|
||
|
||
# Add GitHub pull requests to fetched things via https://git.io/-C-0oQ
|
||
github-add-pulls() {
|
||
git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'
|
||
git config --add remote.upstream.fetch '+refs/pull/*/head:refs/remotes/upstream/-pr/*'
|
||
}
|
||
|
||
# Get server SSL certificate fingerprint in MD5, SHA1 and SHA256.
|
||
# Note that OpenSSL doesn't support IPv6 at time of writing (2015-01-13).
|
||
serversslcertfp() {
|
||
SSSLCFFN=$(openssl s_client -showcerts -connect $1 < /dev/null)
|
||
# To see all validity information
|
||
echo "$SSSLCFFN"
|
||
# For getting the fingerprints
|
||
echo "$SSSLCFFN" | openssl x509 -md5 -fingerprint -noout
|
||
echo "$SSSLCFFN" | openssl x509 -sha1 -fingerprint -noout
|
||
echo "$SSSLCFFN" | openssl x509 -sha256 -fingerprint -noout
|
||
echo "$SSSLCFFN" | openssl x509 -sha512 -fingerprint -noout
|
||
unset SSSLCFFN
|
||
}
|
||
|
||
# The same for local certificate file
|
||
sslcertfp() {
|
||
cat $1 | openssl x509 -md5 -fingerprint -noout
|
||
cat $1 | openssl x509 -sha1 -fingerprint -noout
|
||
cat $1 | openssl x509 -sha256 -fingerprint -noout
|
||
cat $1 | openssl x509 -sha512 -fingerprint -noout
|
||
}
|
||
|
||
# Usage: serversslciphers hostname port
|
||
serversslciphers() {
|
||
nmap -Pn $1 -p $2 --script +ssl-enum-ciphers
|
||
}
|
||
|
||
# Generate SSL certificate
|
||
sslgenpem() {
|
||
openssl req -nodes -newkey rsa:4096 -keyout $1.pem -x509 -days 3650 -out $1.pem -subj "/CN=$2"
|
||
}
|
||
|
||
# Managing SSL certificates of Google Chrome
|
||
chrome-add-cert() {
|
||
echo "Please ensure that either libnss3-tools or nss-tools is installed."
|
||
certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n $1 -i $1
|
||
}
|
||
|
||
chrome-list-certs() {
|
||
echo "Please ensure that either libnss3-tools or nss-tools is installed."
|
||
certutil -d sql:$HOME/.pki/nssdb -L # add '-h all' to see all built-in certs
|
||
}
|
||
|
||
ssldownloadcert() {
|
||
echo "Please ensure that either libnss3-tools or nss-tools is installed."
|
||
echo QUIT | openssl s_client -connect $1:443 | sed -ne '/BEGIN CERT/,/END CERT/p' | tee $1.pem
|
||
}
|
||
|
||
# Getting magnet from transmission-daemon
|
||
transmission-torrents() {
|
||
transmission-remote -l
|
||
}
|
||
transmission-magnet() {
|
||
transmission-remote -l -t $1 -i | \grep magnet | awk -F': ' '{print $2}'
|
||
}
|
||
|
||
# Merges the last $1 commits into one
|
||
git-squash() {
|
||
git reset --soft HEAD~$1
|
||
git commit
|
||
}
|
||
|
||
# Combining mtrp4 & mtrp6
|
||
mtrp() {
|
||
mtrp4 $@
|
||
mtrp6 $@
|
||
}
|
||
|
||
# My IPv4 address
|
||
myip4() {
|
||
if hash dig 2> /dev/null; then
|
||
dig +short myip.opendns.com. A @208.67.222.222
|
||
else
|
||
curl -L4s https://icanhazip.com/
|
||
fi
|
||
}
|
||
|
||
# My IPv6 address
|
||
myip6() {
|
||
if hash dig 2> /dev/null; then
|
||
dig +short myip.opendns.com. AAAA @2620:0:ccc::2
|
||
else
|
||
curl -L6s https://icanhazip.com/
|
||
fi
|
||
}
|
||
|
||
# Easier verifying of SSH signed files: ssh-verify-file whatever@mikaela.info file.txt
|
||
# It's assumed that signature of file.txt is called as file.txt.sig
|
||
sshAllowedSigners=$HOME/src/gitea.blesmrt.net/Mikaela/ssh-allowed_signers/allowed_signers
|
||
ssh-verify-file() {
|
||
echo "$1 ${2:?Usage: ssh-verify-file <email> <file-to-verify>}" > /dev/null
|
||
ssh-keygen -Y verify -f $sshAllowedSigners -I $1 -n file -s $2.sig < $2
|
||
}
|
||
|
||
# I use nvim, while I keep running vim instead
|
||
if hash nvim 2> /dev/null; then
|
||
vim() {
|
||
echo 'using nvim instead'
|
||
/usr/bin/env nvim "$@"
|
||
}
|
||
else
|
||
vim() {
|
||
echo 'nvim not found'
|
||
/usr/bin/env vim "$@"
|
||
}
|
||
fi
|
||
|
||
# In Debian there is "sudo adduser whoever whatever", but I keep forgetting
|
||
# that the more common way is usermod -aG whatever,whereever whoever
|
||
adduser-to-group() {
|
||
usermod -aG "$2" "$1"
|
||
}
|
||
|
||
# Lazyish ACL aware ls
|
||
unalias ls > /dev/null 2>&1
|
||
ls() {
|
||
env ls --all --color=auto --human-readable "$@"
|
||
if hash getfacl 2> /dev/null; then
|
||
if [[ -d "$@" || -f "$@" ]]; then
|
||
printf "\n"
|
||
getfacl --absolute-names --skip-base "$@"
|
||
fi
|
||
fi
|
||
}
|
||
unalias ll > /dev/null 2>&1
|
||
ll() {
|
||
env ls -l --all --color=auto --human-readable "$@"
|
||
if hash getfacl 2> /dev/null; then
|
||
if [[ -d "$@" || -f "$@" ]]; then
|
||
printf "\n"
|
||
getfacl --absolute-names --skip-base "$@"
|
||
fi
|
||
fi
|
||
}
|
||
|
||
# Source files for miscannellious modifications.
|
||
|
||
# acme.sh
|
||
if [ -f ~/.acme.sh/acme.sh.env ]; then
|
||
source ~/.acme.sh/acme.sh.env
|
||
fi
|
||
|
||
# .custom
|
||
if [ -f ~/.custom ]; then
|
||
source ~/.custom
|
||
fi
|
||
|
||
# .zsh_custom
|
||
if [ -f ~/.zsh_custom ]; then
|
||
source ~/.zsh_custom
|
||
fi
|
||
|
||
# Warnings
|
||
if [ -f ~/.warnings ]; then
|
||
source ~/.warnings
|
||
fi
|
||
|
||
# vim: filetype=zsh
|