2023-05-20 11:12:51 +02:00
#!/usr/bin/env zsh
2024-07-20 16:20:24 +02:00
2024-07-21 08:43:53 +02:00
# European/standardizedish English for root
2024-07-20 16:20:24 +02:00
if [ [ " $( id -u) " = = "0" ] ] ; then
2024-07-21 08:43:53 +02:00
unset LC_ALL
2024-07-21 08:54:59 +02:00
unset LANGUAGE
2024-07-21 08:43:53 +02:00
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"
2024-07-20 16:20:24 +02:00
fi
2011-10-29 09:50:56 +02:00
# TOC
2023-02-15 12:29:55 +01:00
# Defaults etc... M0TZLS
# Environment 7RS56S
# Aliases RJ706I
# Functions ZGC5QQ
2011-10-29 09:50:56 +02:00
2024-08-14 06:33:52 +02:00
# lsb_base ?
if [ -f /etc/os-release ] ; then
. /etc/os-release
fi
2024-07-24 12:51:59 +02:00
# 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
(
2024-07-24 18:57:25 +02:00
export LC_ALL = "en_DK.UTF-8"
2024-08-10 06:11:56 +02:00
if hash hostname 2> /dev/null; then
hostname --all-fqdns &
hostname --all-ip-addresses &
elif hash hostnamectl 2> /dev/null; then
hostnamectl hostname &
fi
2024-07-24 12:51:59 +02:00
printf "\n"
printf " $( uptime --pretty) \t $( uptime) \n "
printf "\nPresent:\n"
2024-07-24 18:51:48 +02:00
if hash who 2> /dev/null; then
2024-07-28 10:03:09 +02:00
who --heading --mesg --users
2024-07-24 18:51:48 +02:00
elif hash last 2> /dev/null; then
2024-07-28 10:03:09 +02:00
last --hostlast --present $( date +%R) --fullnames --system --time-format notime
2024-07-24 18:51:48 +02:00
fi
2024-07-24 12:51:59 +02:00
printf "\n"
df / $HOME --human-readable --output= source,fstype,size,used,avail,pcent | uniq
2024-07-24 18:57:25 +02:00
unset LC_ALL
2024-07-24 12:51:59 +02:00
)
2015-09-10 17:56:04 +02:00
2024-07-24 12:51:59 +02:00
# Only print motivational phrases if username is aminda or mikaela
if [ [ $( whoami) = = aminda ] ] || [ [ $( whoami) = = mikaela ] ] ; then
2024-09-26 09:31:41 +02:00
if hash python3 2> /dev/null; then
(
# Motivational messages
# 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
python3 -c ' print( "" "
Aferoj emas funkcii sin mem...\t OM MANI PEME HUNG...
\t \t \t Foci
\t Fluff the SPOTLIGHT EFFECT!
\t Leave the world a better place than you found it.
\t May your heart be your guiding key ; )
"" " )'
)
fi
2024-07-24 12:51:59 +02:00
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
2015-09-10 17:56:04 +02:00
2023-02-15 12:29:55 +01:00
##### Defaults etc... M0TZLS #####
2011-09-29 14:25:05 +02:00
# This is based on zshrc which came with Debian (Third option in wizard for new users.)
2014-10-07 07:41:24 +02:00
# Save history
export HISTSIZE = 99999
export SAVEHIST = $HISTSIZE
setopt hist_ignore_all_dups
export HISTFILE = ~/.zsh_history
setopt INC_APPEND_HISTORY
setopt SHARE_HISTORY
2011-09-29 14:25:05 +02:00
# Set up the prompt
autoload -Uz promptinit
2013-02-09 15:46:22 +01:00
2018-10-11 11:56:34 +02:00
# Green for normal user and red for root
2011-09-29 14:25:05 +02:00
promptinit
2013-02-09 15:46:22 +01:00
2018-10-11 11:56:34 +02:00
if [ $USER = "root" ] ; then
2023-02-15 12:29:55 +01:00
prompt elite2 red
2018-10-11 11:56:34 +02:00
else
2023-02-15 12:29:55 +01:00
prompt elite2 green
2018-10-11 11:56:34 +02:00
fi
2011-09-29 14:25:05 +02:00
2024-05-29 06:39:46 +02:00
# Newline before new prompt
precmd( ) {
precmd( ) {
printf "\n"
}
}
2011-09-29 14:25:05 +02:00
# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e
# Use modern completion system
autoload -Uz compinit
2024-10-29 08:37:22 +01:00
# -i = exclude insecure directories, -u would disable security checks
# https://github.com/zsh-users/zsh/blob/zsh-5.9/Completion/compinit#L67-L72
compinit -i
2011-09-29 14:25:05 +02:00
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
2024-07-14 15:32:27 +02:00
#zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
2011-09-29 14:25:05 +02:00
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'
2024-07-24 11:30:34 +02:00
if hash dircolors 2> /dev/null; then
eval $( dircolors --bourne-shell)
2024-08-04 13:07:52 +02:00
#alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
2023-10-09 11:05:39 +02:00
fi
2020-05-02 12:43:23 +02:00
2023-02-15 12:29:55 +01:00
##### Environment 7RS56S #####
2011-10-29 09:50:56 +02:00
# Environment should be placed to .environment or .zsh_environment (or .zshenv).
# Source before mentioned locations if they exist.
# .environment
if [ -f ~/.environment ] ; then
2023-02-15 12:29:55 +01:00
source ~/.environment
2011-10-29 09:50:56 +02:00
fi
# .zsh_environment
if [ -f ~/.zsh_environment ] ; then
2023-02-15 12:29:55 +01:00
source ~/.zsh_environment
2011-10-01 15:32:18 +02:00
fi
2011-10-29 09:50:56 +02:00
# .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).
2011-10-01 15:32:18 +02:00
if [ -f ~/.zshenv ] ; then
2023-02-15 12:29:55 +01:00
source ~/.zshenv
2011-10-01 15:32:18 +02:00
fi
2012-09-16 14:24:34 +02:00
# Enable core files.
2024-07-14 15:34:10 +02:00
( ulimit -c unlimited & )
2012-09-16 14:24:34 +02:00
2023-02-15 12:29:55 +01:00
# More colours
2011-12-29 10:18:28 +01:00
if [ [ $TERM = = 'xterm' ] ] ; then
2024-07-14 15:34:10 +02:00
export TERM = xterm-256color
2011-12-29 10:18:28 +01:00
fi
2023-02-15 12:29:55 +01:00
if [ [ $TERM = = 'screen' ] ] ; then
2024-07-14 15:34:10 +02:00
export TERM = screen-256color
2011-12-29 10:20:01 +01:00
fi
2012-04-30 18:12:20 +02:00
# Sets the default editor.
2023-02-15 12:47:57 +01:00
#export EDITOR=nvim # MIKAELA_GREP MIKAELA_GREP_ENVIRONMENT
2011-10-29 09:50:56 +02:00
2015-09-12 11:07:40 +02:00
# Set TZ to local timezone for sending over SSH
TZ = $( date +%Z)
2011-10-29 09:50:56 +02:00
2023-02-15 12:29:55 +01:00
# Sets PATH. To add another path, add :</path/to/new/path> to string below.
2024-08-14 06:29:57 +02:00
PATH = $HOME /.local/bin:$HOME /bin:$HOME /Persistent/.local/bin:$HOME /Persistent/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
2014-04-29 14:23:54 +02:00
2012-12-21 14:24:51 +01:00
# Colours to less
2020-01-02 15:08:42 +01:00
# Copied from https://nion.modprobe.de/blog/archives/572-less-colors-for-man-pages.html
2012-12-21 14:24:51 +01:00
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'
2011-10-29 09:50:56 +02:00
2020-03-03 20:18:21 +01:00
# 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
2023-02-15 12:29:55 +01:00
export SSH_AUTH_SOCK = $( gpgconf --list-dirs agent-ssh-socket)
gpgconf --launch gpg-agent
2024-07-14 15:34:10 +02:00
gpg-connect-agent updatestartuptty /bye > /dev/null 2>& 1
2020-03-03 20:18:21 +01:00
# otherwise use the normal ssh-agent
else
2023-02-15 12:29:55 +01:00
# 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
2020-03-03 20:18:21 +01:00
fi
2013-02-16 09:11:40 +01:00
2014-04-20 20:39:30 +02:00
# If we are on Linux, enable apt progress bar and colours
2024-06-26 16:55:57 +02:00
#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
2014-04-20 11:37:56 +02:00
2014-05-01 13:55:01 +02:00
# OS X ls colours (copied from https://apple.stackexchange.com/questions/33677/
2024-08-04 13:07:52 +02:00
#export CLICOLOR=1
#export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
2014-05-01 13:55:01 +02:00
2024-04-23 18:26:33 +02:00
# 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.
2024-07-30 19:42:10 +02:00
export RES_OPTIONS = "timeout:1 attempts:5 rotate edns0 trust-ad"
2024-04-23 18:26:33 +02:00
2024-07-16 11:22:57 +02:00
# https://github.com/go-nv/goenv
2024-07-28 15:43:01 +02:00
if [ -f /home/linuxbrew/.linuxbrew/opt/goenv/bin/goenv ] ; then
2024-07-30 13:14:37 +02:00
eval " $( /home/linuxbrew/.linuxbrew/opt/goenv/bin/goenv init -) " > /dev/null 2>& 1
2024-07-28 15:43:01 +02:00
PATH = /home/linuxbrew/.linuxbrew/opt/goenv/bin/shims:$PATH
elif [ -f ~/.goenv/bin/goenv ] ; then
2024-07-30 13:14:37 +02:00
eval " $( ~/.goenv/bin/goenv init -) " > /dev/null 2>& 1
2024-07-16 11:22:57 +02:00
fi
2024-07-06 07:35:13 +02:00
# https://github.com/nvm-sh/nvm
2024-07-28 15:43:01 +02:00
if [ -d /home/linuxbrew/.linuxbrew/opt/nvm ] ; then
2024-07-28 07:32:41 +02:00
mkdir -p /home/linuxbrew/.nvm
export NVM_DIR = /home/linuxbrew/.nvm
2024-07-28 10:49:51 +02:00
. /home/linuxbrew/.linuxbrew/opt/nvm/nvm.sh
2024-07-28 15:43:01 +02:00
elif [ -d ~/.nvm ] ; then
. ~/.nvm/nvm.sh
. ~/.nvm/bash_completion
2024-07-06 07:35:13 +02:00
fi
2024-07-06 08:01:48 +02:00
# https://github.com/rbenv/rbenv
2024-07-28 15:43:01 +02:00
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
2024-07-30 10:28:49 +02:00
# No OpenSSL? Remember (and substitute the x, y and z)!:
# rbenv install -- --with-openssl-dir=/home/linuxbrew/.linuxbrew/Cellar/openssl@x/x.y.z/
2024-07-28 15:43:01 +02:00
elif [ -f ~/.rbenv/bin/rbenv ] ; then
eval " $( ~/.rbenv/bin/rbenv init -) "
2024-07-06 08:50:04 +02:00
# Remember! And verify it before running!
# git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
2024-07-06 08:01:48 +02:00
fi
2024-07-06 09:04:55 +02:00
# Add RubyGems to PATH
2024-07-14 15:34:10 +02:00
if hash ruby 2> /dev/null; then
2024-07-06 09:04:55 +02:00
PATH = " $( ruby -e 'print Gem.user_dir' ) /bin: $PATH "
fi
2024-07-06 08:01:48 +02:00
# https://github.com/pyenv/pyenv
2024-07-28 15:43:01 +02:00
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 -) "
2024-07-06 11:02:18 +02:00
# 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
2024-07-06 08:01:48 +02:00
fi
2024-07-06 07:16:06 +02:00
# https://github.com/nodenv/nodenv
2024-07-28 15:43:01 +02:00
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 -) "
2024-07-06 07:16:06 +02:00
# Remember! And verify it before running!
# git clone https://github.com/nodenv/node-build.git "$(nodenv root)"/plugins/node-build
fi
2024-07-28 06:18:12 +02:00
# https://github.com/Homebrew/brew
if [ -d /home/linuxbrew/.linuxbrew/bin ] ; then
eval $( /home/linuxbrew/.linuxbrew/bin/brew shellenv)
fi
2024-07-06 09:04:55 +02:00
# 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]}' )
2023-02-15 12:29:55 +01:00
##### Aliases RJ706I #####
2011-10-29 09:50:56 +02:00
2024-07-12 11:50:09 +02:00
# To get sudo work with aliases. And workaround nvim/tmux crash.
alias sudo = "\sudo --preserve-env=tmux"
2011-10-29 09:50:56 +02:00
# Moving between directories:
alias ..= "cd .."
2020-02-13 13:14:33 +01:00
# Use htop instead of top if available
2024-07-14 15:34:10 +02:00
if hash htop 2> /dev/null; then
2023-02-15 12:29:55 +01:00
alias top = "htop"
2020-02-13 13:14:33 +01:00
fi
2011-10-29 09:50:56 +02:00
2014-07-30 19:23:13 +02:00
# Add title to youtube-dl & make yle-dl Windows-friendly
2019-04-04 19:41:40 +02:00
alias youtube-dl= "youtube-dl -o '%(title)s-%(id)s.%(ext)s'"
2014-07-30 19:23:13 +02:00
alias yle-dl= "yle-dl --vfat"
2011-10-29 09:50:56 +02:00
# 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"
2014-01-14 20:34:37 +01:00
# Show compilation date of WeeChat.
alias weechat-version= "weechat --help|head -n2"
2011-10-29 09:50:56 +02:00
2020-02-13 13:14:33 +01:00
# NMAP specific. All nmap things should be run with sudo.
2011-10-29 09:50:56 +02:00
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 "
2023-02-15 12:29:55 +01:00
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 "
2023-02-21 18:08:54 +01:00
# 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.
2011-10-29 09:50:56 +02:00
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.
2012-01-10 15:54:10 +01:00
alias rdownload = "rsync -h --progress -avz "
2013-02-24 09:03:32 +01:00
alias rscp = 'rsync -h --progress -avz '
alias rscpr = 'rsync -h --progress -azvv '
2011-10-29 09:50:56 +02:00
# TMUX specific
2014-10-29 20:13:08 +01:00
alias tmux = "tmux -2u"
2014-05-29 15:02:08 +02:00
alias attach = "tmux attach-session"
alias detach = "tmux detach"
2011-10-29 09:50:56 +02:00
2012-04-30 18:12:20 +02:00
# Supybot specifig. Why to write long command, if you can write short command?
2014-09-11 08:33:33 +02:00
alias supybot-config-reload= "killall -HUP supybot "
alias supybot-owner-quit= "killall -INT supybot "
2011-10-29 09:50:56 +02:00
# Translating plugins in Limnoria
2012-04-15 17:46:00 +02:00
alias supybot-generate-messages.pot= "pygettext --docstrings config.py plugin.py"
2020-02-13 13:14:33 +01:00
alias supybot-generate-messages.pot-xgettext= "xgettext --language=Python config.py plugin.py && mv -f messages.po messages.pot"
2012-08-04 14:26:07 +02:00
alias supybot-check-plugin-trans= "sandbox/check_trans.py plugins/"
2014-09-11 08:37:33 +02:00
alias supybot-check-core-trans= "sandbox/check_trans.py --core"
2012-10-07 17:25:38 +02:00
alias supybot-generate-messages.pot-mass= "find . -type d -exec sh -c '(cd {} && pygettext --docstrings config.py plugin.py)' ';'"
2011-10-29 09:50:56 +02:00
# ZSH specific.
# I think that "theme" is more describing than "prompt".
alias theme = "prompt "
## -- Start of aliases which are saved from Ubuntu default bashrc. --
2024-08-04 13:07:52 +02:00
#alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
2024-05-29 14:19:06 +02:00
alias grep = 'grep --color=auto'
alias fgrep = 'fgrep -F --color=auto'
alias egrep = 'egrep -E --color=auto'
2023-02-21 18:08:54 +01:00
# Add an "alert" alias for long running commands. Use like so:
2011-10-29 09:50:56 +02:00
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$//' \' ')"'
2020-02-13 13:14:33 +01:00
## -- End of aliases which are saved from Ubuntu default bashrc. --
2011-10-29 09:50:56 +02:00
2022-05-10 21:53:38 +02:00
# Enable colours for diff when in terminal
alias diff = "diff --color=auto"
2011-10-29 09:50:56 +02:00
# SSHGuard specific
2015-10-25 13:10:01 +01:00
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"
2011-10-29 09:50:56 +02:00
# Enter ban number as arguement. You can see ban numbers with previous command.
2015-10-25 13:10:01 +01:00
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"
2011-10-29 09:50:56 +02:00
2011-12-25 16:51:34 +01:00
# For locally rsync copying folder1 to folder2.
2012-01-10 15:54:10 +01:00
alias rsync-folder= "rsync -h --progress -azvv "
2011-12-25 16:51:34 +01:00
2011-12-31 21:11:01 +01:00
# SSHGuard seems to prefer users to run this always when connecting with keys in ssh-agent...
2012-04-01 16:21:38 +02:00
# Use GPG2 instead of GPG!
2024-07-14 15:34:10 +02:00
if hash gpg2 2> /dev/null; then
2023-02-15 12:29:55 +01:00
alias gpg = gpg2
export KEYBASE_GPG = gpg2
2020-02-13 13:14:33 +01:00
fi
2014-05-28 18:20:12 +02:00
alias gpg-fix-tty= 'export GPG_TTY=$(tty)'
2012-07-25 09:51:05 +02:00
# Amount of keys in GPG keyring.
alias gpg-key-amount= "gpg --list-keys|grep '^pub'|wc -l"
2012-07-25 10:00:52 +02:00
alias gpg-key-count= "gpg --export -a|gpg --import"
2012-07-25 09:51:05 +02:00
2015-07-31 17:07:54 +02:00
# Current IPv4 and IPv6 addresses. Calls functions.
2015-02-01 12:32:50 +01:00
alias myip = "myip4 && myip6"
2012-08-18 10:37:19 +02:00
2020-01-02 15:08:42 +01:00
# Update groups without logging out. Requires entering password. Source: https://blog.edwards-research.com/2010/10/linux-refresh-group-membership-without-logging-out/
2012-08-31 16:48:55 +02:00
alias refreshgroups = " exec su -l $USER "
2012-08-30 18:55:53 +02:00
2012-09-15 09:12:17 +02:00
# 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.
2024-07-14 15:34:10 +02:00
alias cls = clear # MSDOS
alias help = man # MSDOS
2012-09-15 09:12:17 +02:00
alias ipconfig = ifconfig # MSDOS
2024-07-14 15:34:10 +02:00
alias copy = cp # MSDOS
alias move = mv # MSDOS
2012-09-15 09:12:17 +02:00
2012-09-15 10:01:06 +02:00
# List git committers of repository
alias git-committers= "git shortlog -s"
2014-05-29 23:01:03 +02:00
alias git-changelog= "git log --oneline --decorate"
alias git-changelog-color= "git log --oneline --decorate --color"
2012-09-15 10:01:06 +02:00
2020-02-13 13:14:33 +01:00
# Line ending converting with flip
2012-09-23 09:27:29 +02:00
alias unixle = "flip -ub "
alias msdosle = "flip -mb "
2012-12-21 11:54:59 +01:00
# 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 "
2020-02-13 13:14:33 +01:00
# I have function ex so these are ex-* to avoid conflict.
2012-12-21 11:54:59 +01:00
# 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 "
2013-01-14 17:13:46 +01:00
# systemd runlevels/targets
alias currenttargets = "systemctl list-units --type=target"
alias telsystemd = "systemctl isolate "
alias defaulttarget = "systemctl enable "
2012-12-31 22:00:59 +01:00
# For getting timestamps in history
alias history = "history -i "
2012-12-22 20:17:56 +01:00
# To have less handle ls colours
alias less = "less -R "
2012-12-21 11:54:59 +01:00
2024-07-12 11:50:09 +02:00
# "su -" with/without sudo. Conflicts with SailfishOS, to learn to use sui
# instead.
2024-07-15 08:04:09 +02:00
if ! hash ssu 2> /dev/null; then
alias ssu = "echo 'No.'"
fi
2024-07-12 11:50:09 +02:00
alias sui = "sudo -i"
2024-07-15 08:04:09 +02:00
alias sudoi = "sudo -i"
2024-07-12 11:50:09 +02:00
#alias suu="su -"
2013-01-01 10:30:37 +01:00
2013-02-16 08:52:19 +01:00
# Who command which I use with Conky
alias cwho = "who -H -w -u"
2020-01-02 18:55:44 +01:00
# inxi - https://smxi.org/docs/inxi.htm
2024-04-25 16:39:20 +02:00
#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"
2020-02-13 13:14:33 +01:00
#alias inxi-update="inxi -U"
2014-01-08 20:18:57 +01:00
2022-03-17 13:24:29 +01:00
# FINEID to ssh-agent
alias fineid = "ssh-add -s /usr/lib64/libcryptoki.so"
2014-04-14 17:40:47 +02:00
2014-05-13 14:58:09 +02:00
# OS X
2020-02-13 13:14:33 +01:00
# What is this?
#alias osx-server-caching-interface="serveradmin settings caching:Interface ="
2014-05-13 15:00:13 +02:00
alias osx-show-hidden-files= "defaults write com.apple.finder AppleShowAllFiles"
2020-02-13 13:14:33 +01:00
# Workaround on unsupported devices?
2014-05-13 14:58:09 +02:00
alias osx-airdrop-listenallif= "defaults write com.apple.NetworkBrowser BrowseAllInterfaces"
alias osx-set-updatecheck= "defaults write /Library/Preferences/com.apple.SoftwareUpdate ScheduleFrequency"
2014-05-01 17:21:08 +02:00
2014-05-22 11:05:13 +02:00
# Resetting different desktop environments
2020-02-13 13:14:33 +01:00
# 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"
2014-05-30 23:02:01 +02:00
2014-06-05 15:36:20 +02:00
# Show information on PEM file.
alias peminfo = "openssl x509 -text -in"
2014-06-28 07:03:28 +02:00
# tmux emergency attach
alias tmuxeattach = " /proc/ $( pgrep -o tmux) /exe attach "
2014-07-15 19:42:09 +02:00
# Reset configuration files on systems using apt
alias purgeconfig = "apt-get install --reinstall -o DPkg::options::=--force-confask"
2015-04-26 17:20:21 +02:00
# Send command output to sprunge.us or ix.io `command|<sprungeus|ixio>`
2020-01-02 15:08:42 +01:00
alias sprungeus = "curl -F 'sprunge=<-' https://sprunge.us"
2015-04-26 17:20:21 +02:00
alias ixio = "curl -F 'f:1=<-' ix.io"
2014-07-30 19:34:51 +02:00
2014-08-15 16:54:33 +02:00
# Copy-paste mtr output more easily
2014-12-30 17:31:16 +01:00
alias mtrp4 = "mtr -rw4c 10"
alias mtrp6 = "mtr -rw6c 10"
2014-08-15 16:54:33 +02:00
2020-05-29 13:12:54 +02:00
# Simple HTTPd with Python.
alias python-httpd= "python3 -m http.server"
2014-09-04 12:27:56 +02:00
# pip
2023-09-24 13:33:07 +02:00
alias pip = "python3 -m pip"
2014-09-04 12:27:56 +02:00
alias pip3 = "python3 -m pip"
2023-09-24 13:33:07 +02:00
alias pypypip = "pypy3 -m pip"
2020-02-13 13:14:33 +01:00
alias pypypip3 = "pypy3 -m pip"
2023-10-13 16:52:17 +02:00
alias pipx = "python3 -m pipx"
alias pipx3 = "python3 -m pipx"
alias pypypipx = "pypy3 -m pipx"
alias pypypipx3 = "pypy3 -m pipx"
2014-09-11 08:32:02 +02:00
2020-05-29 13:12:54 +02:00
# Python virtualenv/the new venv comparsion:
# https://virtualenv.pypa.io/en/latest/#virtualenv / python3-venv (Debian)
alias venv = "python3 -m venv"
2023-09-24 13:33:07 +02:00
alias pypyvenv = "pypy3 -m venv"
alias venvpypy = pypyvenv
2020-05-29 13:12:54 +02:00
2014-09-13 10:26:28 +02:00
# cp/mv using rsync. rcp appears to be link to scp in my system, so I can
# safely use this alias.
2024-07-14 15:34:10 +02:00
if hash rsync 2> /dev/null; then
2023-02-15 12:29:55 +01:00
alias rcp = "rsync -a --progress"
alias rmv = "rsync -a --progress --remove-source-files"
2020-02-13 13:14:33 +01:00
fi
2014-09-13 10:26:28 +02:00
2014-12-28 08:22:31 +01:00
# Clear apt list cache
2015-11-14 11:48:13 +01:00
alias clear-apt-list-cache= "cd /var/lib/apt/lists && rm -f *|true && cd partial && rm -f *|true && cd"
2014-12-28 08:22:31 +01:00
2015-01-07 08:30:52 +01:00
# Accept all cookies with Lynx, makes browsing easier and
# every other browser does this too.
alias lynx = "lynx -accept_all_cookies"
2015-01-27 10:11:43 +01:00
# Cat multiple files preserving filenames
2020-01-02 15:08:42 +01:00
# via https://stackoverflow.com/a/7816490
2015-01-27 10:11:43 +01:00
alias multicat = 'tail -n +1'
2015-02-02 11:32:20 +01:00
# Getting SSIDs and keys from connmann (Jolla)
2015-02-02 12:34:09 +01:00
alias connman-wlans= 'grep -E "Name|Passphrase" /var/lib/connman/wifi*/settings --no-filename'
2015-02-02 11:32:20 +01:00
2015-02-12 12:59:33 +01:00
# Turn input into lowercase and remove colons.
# Meant for SSL certificates (IRC))
alias lowernocolon = "tr -d ':' | tr 'A-Z' 'a-z'"
2015-06-12 17:20:15 +02:00
# Sailfish Network status, via IRC
alias sailfish-nstatus= 'dbus-send --system --type=method_call --print-reply --dest=net.connman / net.connman.Manager.GetServices|less'
2015-07-22 14:41:26 +02:00
# apt build depedencies (without installing)
alias apt-builddep= "apt-rdepends --build-depends --follow=DEPENDS"
2020-02-13 13:14:33 +01:00
# https://superuser.com/a/638033 - get embedded Windows product key
2015-08-22 14:13:22 +02:00
alias winkey = "xxd /sys/firmware/acpi/tables/MSDM"
2022-04-15 10:54:02 +02:00
# Always exec startx/startsway/wayland/sway so Ctrl-Alt-Backspace won't lead to unlocked TTY.
2022-04-15 17:33:51 +02:00
#alias startsway="exec dbus-launch --exit-with-session sway --unsupported-gpu"
alias startsway = "\exec startsway"
alias startplasma = "\exec startplasma"
2022-04-15 10:54:02 +02:00
#alias startx="exec \startx"
alias startx = startsway
alias startwayland = startsway
alias startwl = startsway
2019-02-18 12:20:04 +01:00
2019-08-26 19:31:41 +02:00
# cat list of kernel detected vulnerabilities/states with filenames
alias linux-check-cpu-vulns= "tail -n +1 /sys/devices/system/cpu/vulnerabilities/*"
2020-02-15 18:10:05 +01:00
# gpg web key directory lookup
alias wkdlookup = "gpg --auto-key-locate nodefault,wkd --locate-keys"
2020-05-09 23:51:02 +02:00
# Debian key server, Tor not necessary due to dirmngr config
alias gpg-dkr-recv= "gpg --keyserver hkps://keyring.debian.org --recv-keys"
2020-02-15 18:10:05 +01:00
# 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"
2021-06-24 15:54:21 +02:00
# helpful for wkd
2020-02-16 16:59:06 +01:00
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"
2020-02-15 18:10:05 +01:00
# ports that are being listened to
2020-12-17 07:05:52 +01:00
alias netstat-listening-ports= "netstat -plntu"
2020-02-15 18:10:05 +01:00
2020-04-05 17:08:20 +02:00
# mpv music & music shuffle
alias mpvm = "mpv --no-video"
alias mpvms = "mpv --no-video --shuffle"
2020-10-26 18:19:18 +01:00
# Compatibility with my i3 alsactl mess
2024-07-14 15:34:10 +02:00
if [ -f ~/.config/asound.state ] ; then
2023-02-21 18:08:54 +01:00
alias alsactl = "\alsactl -f ~/.config/asound.state"
2020-10-26 18:19:18 +01:00
fi
2022-03-17 13:56:50 +01:00
# 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"
2024-01-01 14:24:04 +01:00
# Anywhere on Earth date, https://en.m.wikipedia.org/wiki/Anywhere_on_Earth
alias aoedate = "TZ=Etc/GMT+12 date"
2024-05-29 14:26:43 +02:00
# verbosity to common actions
alias rm = "\rm --verbose"
alias ln = "\ln --verbose"
alias mkdir = "\mkdir --verbose"
alias chattr = "\chattr -V"
2024-05-29 14:37:28 +02:00
alias chmod = "\chmod --verbose"
2024-06-21 05:45:41 +02:00
# https://github.com/nodejs/corepack/blob/v0.28.2/README.md#corepack-enable--name
2024-07-14 15:34:10 +02:00
if hash corepack 2> /dev/null; then
2024-06-26 17:05:34 +02:00
alias yarn = "corepack yarn"
alias yarnpkg = "corepack yarnpkg"
alias pnpm = "corepack pnpm"
alias pnpx = "corepack pnpx"
alias npm = "corepack npm"
alias npx = "corepack npx"
2024-07-14 15:34:10 +02:00
if ! hash prettier 2> /dev/null; then
2024-07-14 13:58:51 +02:00
alias prettier = "corepack pnpx prettier --cache --ignore-unknown"
2024-06-26 17:05:34 +02:00
fi
else
2024-07-06 07:36:09 +02:00
echo "Information: corepack is not installed."
2024-06-26 17:05:34 +02:00
fi
2024-05-29 14:37:28 +02:00
2024-06-26 16:55:57 +02:00
# https://pnpm.io/installation#using-a-shorter-alias
alias pn = "corepack pnpm"
2024-06-21 11:34:39 +02:00
2024-05-29 14:37:28 +02:00
# github-pages etc.
2024-07-14 15:34:10 +02:00
if hash bundle 2> /dev/null; then
2024-05-29 14:37:28 +02:00
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"
2024-05-29 14:26:43 +02:00
2024-07-21 06:15:55 +02:00
# 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"
2024-08-08 07:08:24 +02:00
# To complement my nordvpn-off wrapper
alias nordvpn-offf= "sudo systemctl stop nordvpnd.service;sudo systemctl stop nordvpnd.socket"
alias nordvpn-off2= nordvpn-offf
2015-07-22 14:42:57 +02:00
# Allow custom aliases to be put in .aliases or .zsh_aliases .
2011-10-29 09:50:56 +02:00
# .aliases
if [ -f ~/.aliases ] ; then
2023-02-15 12:29:55 +01:00
source ~/.aliases
2011-10-29 09:50:56 +02:00
fi
# .zsh_aliases
if [ -f ~/.zsh_aliases ] ; then
2023-02-15 12:29:55 +01:00
source ~/.zsh_aliases
2011-10-01 15:32:18 +02:00
fi
2023-02-15 12:29:55 +01:00
##### Functions ZGC5QQ #####
2011-10-29 09:50:56 +02:00
2020-01-02 15:08:42 +01:00
# GEOIP lookup, improved from the ultimate bashrc https://goo.gl/qGK5j
2011-10-29 09:50:56 +02:00
function geoip( ) {
2023-02-15 12:29:55 +01:00
geoiplookup $1
geoiplookup6 $1
2011-10-29 09:50:56 +02:00
}
2020-02-13 13:14:33 +01:00
# TODO: Is it bash or zshrc?
2020-01-02 15:08:42 +01:00
# ex command. Copied from zshrc of bioterror ( https://ricecows.org/configs/zsh/.zshrc ). Original comment below:
2011-10-29 09:50:56 +02:00
## for unit193 ;)
## use command "ex" to extract any archive files.
## "ex package.zip" for example
2024-07-14 15:34:10 +02:00
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
2023-02-21 18:08:54 +01:00
else
2024-07-14 15:34:10 +02:00
echo "" ${ 1 } " is not a valid file"
fi
2011-10-29 09:50:56 +02:00
}
2012-01-06 19:24:36 +01:00
# Given by nyuszika7h. Shortens GitHub URLs with git.io
2012-04-24 16:30:37 +02:00
function gitio( ) {
2023-02-15 12:29:55 +01:00
curl -s -i https://git.io -F " url= $1 " | grep --color= never -P '^Location: ' | awk '{ print $2 }'
2012-04-24 16:30:37 +02:00
}
function mkcd( ) {
2023-02-15 12:29:55 +01:00
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 "
2012-04-24 16:30:37 +02:00
}
function gribble-gpg-everify( ) {
2023-02-15 12:29:55 +01:00
# 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
2012-04-24 16:30:37 +02:00
}
2012-01-06 19:24:36 +01:00
2014-05-06 16:12:33 +02:00
# This function will install/upgrade shell-things.
function shell-things {
2024-07-14 15:34:10 +02:00
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
2024-08-10 11:46:33 +02:00
git remote set-url origin https://codeberg.org/Aminda/shell-things.git
2024-07-14 15:34:10 +02:00
git fetch --all
2024-08-12 09:46:20 +02:00
git checkout -b cxefa origin/cxefa > /dev/null 2>& 1
2024-07-14 15:34:10 +02:00
git pull
2024-08-10 11:46:33 +02:00
echo "git config --global gpg.ssh.allowedSignersFile ~/src/codeberg.org/Aminda/ssh-allowed_signers/allowed_signers"
2024-07-30 13:20:32 +02:00
git verify-commit HEAD || exit 1
2024-07-14 15:34:10 +02:00
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 ""
2024-08-10 11:46:33 +02:00
git clone https://codeberg.org/Aminda/shell-things.git $SHELL_THINGS_REPO
2024-07-14 15:34:10 +02:00
cd $SHELL_THINGS_REPO
sleep 10
echo ""
echo "shell-things: Installing/Upgrading..."
echo ""
fi
2014-05-06 16:12:33 +02:00
2024-07-14 15:34:10 +02:00
# Installing...
bash -x ./install
2023-02-15 12:29:55 +01:00
echo ""
2024-07-14 15:34:10 +02:00
echo "shell-things: Installing finished."
2023-02-15 12:29:55 +01:00
echo ""
2024-07-14 15:34:10 +02:00
2023-02-15 12:29:55 +01:00
echo ""
2024-07-14 15:34:10 +02:00
echo "shell-things: Everything is now done :)"
2023-02-15 12:29:55 +01:00
echo ""
2014-05-06 16:12:33 +02:00
2024-07-14 15:34:10 +02:00
cd
2014-05-06 16:12:33 +02:00
}
2014-07-17 15:05:42 +02:00
# This function removes and regenerates ssh host keys.
2020-02-13 13:14:33 +01:00
#ssh-regen-host-keys () {
2023-02-15 12:29:55 +01:00
# 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
2020-02-13 13:14:33 +01:00
#}
2014-07-17 15:05:42 +02:00
2014-07-30 19:40:44 +02:00
# This function erases Master Boot Record from device
# Note: this is dangerous so this function will echo the command
# instad of running it!
2020-02-13 13:14:33 +01:00
#erase-mbr() {
2023-02-15 12:29:55 +01:00
# echo dd if=/dev/zero of=$1 bs=512 count=2
2020-02-13 13:14:33 +01:00
#}
2014-07-30 19:40:44 +02:00
2014-09-19 23:08:16 +02:00
# 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.
2024-07-14 15:34:10 +02:00
if hash clang 2> /dev/null; then
2023-02-15 12:29:55 +01:00
export CC = clang
export HOMEBREW_CC = clang
2014-09-19 23:08:16 +02:00
fi
2024-07-14 15:34:10 +02:00
if hash clang++ 2> /dev/null; then
2023-02-15 12:29:55 +01:00
export CXX = clang++
2014-09-19 23:08:16 +02:00
fi
2020-01-02 15:08:42 +01:00
# Add GitHub pull requests to fetched things via https://git.io/-C-0oQ
2014-10-05 21:50:06 +02:00
github-add-pulls( ) {
2023-02-15 12:29:55 +01:00
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/*'
2014-10-05 21:50:06 +02:00
}
2014-09-19 23:08:16 +02:00
2014-12-21 14:46:11 +01:00
# Get server SSL certificate fingerprint in MD5, SHA1 and SHA256.
2015-01-13 19:09:48 +01:00
# Note that OpenSSL doesn't support IPv6 at time of writing (2015-01-13).
2024-07-14 15:34:10 +02:00
serversslcertfp( ) {
2023-02-15 12:29:55 +01:00
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
2014-12-21 14:46:11 +01:00
}
2015-02-03 08:14:26 +01:00
# The same for local certificate file
2024-07-14 15:34:10 +02:00
sslcertfp( ) {
2023-02-15 12:29:55 +01:00
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
2015-02-03 08:14:26 +01:00
}
2015-02-09 12:54:42 +01:00
# Usage: serversslciphers hostname port
serversslciphers( ) {
2023-02-15 12:29:55 +01:00
nmap -Pn $1 -p $2 --script +ssl-enum-ciphers
2015-02-09 12:54:42 +01:00
}
2015-02-12 12:56:40 +01:00
# Generate SSL certificate
2024-07-14 15:34:10 +02:00
sslgenpem( ) {
2023-02-15 12:29:55 +01:00
openssl req -nodes -newkey rsa:4096 -keyout $1 .pem -x509 -days 3650 -out $1 .pem -subj " /CN= $2 "
2015-02-12 12:56:40 +01:00
}
2015-04-22 18:21:03 +02:00
# Managing SSL certificates of Google Chrome
2024-07-14 15:34:10 +02:00
chrome-add-cert( ) {
2023-02-15 12:29:55 +01:00
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
2015-04-22 18:21:03 +02:00
}
2024-07-14 15:34:10 +02:00
chrome-list-certs( ) {
2023-02-15 12:29:55 +01:00
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
2015-04-22 18:21:03 +02:00
}
2024-07-14 15:34:10 +02:00
ssldownloadcert( ) {
2023-02-15 12:29:55 +01:00
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
2015-04-22 18:21:03 +02:00
}
2015-06-12 18:28:10 +02:00
# Getting magnet from transmission-daemon
2024-07-14 15:34:10 +02:00
transmission-torrents( ) {
2023-02-15 12:29:55 +01:00
transmission-remote -l
2015-06-12 18:28:10 +02:00
}
2024-07-14 15:34:10 +02:00
transmission-magnet( ) {
2023-02-15 12:29:55 +01:00
transmission-remote -l -t $1 -i | \g rep magnet | awk -F': ' '{print $2}'
2015-06-12 18:28:10 +02:00
}
2016-04-11 08:55:27 +02:00
# Merges the last $1 commits into one
2024-07-14 15:34:10 +02:00
git-squash( ) {
2023-02-15 12:29:55 +01:00
git reset --soft HEAD~$1
git commit
2015-06-12 18:30:23 +02:00
}
2015-06-12 18:28:10 +02:00
2015-06-24 19:03:40 +02:00
# Combining mtrp4 & mtrp6
2015-06-24 19:06:54 +02:00
mtrp( ) {
2023-02-15 12:29:55 +01:00
mtrp4 $@
mtrp6 $@
2015-06-24 19:03:40 +02:00
}
2015-07-31 17:07:54 +02:00
# My IPv4 address
2024-07-14 15:34:10 +02:00
myip4( ) {
if hash dig 2> /dev/null; then
2023-02-15 12:29:55 +01:00
dig +short myip.opendns.com. A @208.67.222.222
else
curl -L4s https://icanhazip.com/
fi
2015-07-31 17:07:54 +02:00
}
# My IPv6 address
2024-07-14 15:34:10 +02:00
myip6( ) {
if hash dig 2> /dev/null; then
2023-02-15 12:29:55 +01:00
dig +short myip.opendns.com. AAAA @2620:0:ccc::2
else
curl -L6s https://icanhazip.com/
fi
2015-07-31 17:07:54 +02:00
}
2022-03-17 14:00:15 +01:00
# 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
2024-08-10 11:46:33 +02:00
sshAllowedSigners = $HOME /src/codeberg.org/Aminda/ssh-allowed_signers/allowed_signers
2024-07-14 15:34:10 +02:00
ssh-verify-file( ) {
2023-02-15 12:29:55 +01:00
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
2022-03-17 14:00:15 +01:00
}
2023-10-19 08:51:32 +02:00
# I use nvim, while I keep running vim instead
2024-07-14 15:34:10 +02:00
if hash nvim 2> /dev/null; then
2023-10-19 08:51:32 +02:00
vim( ) {
echo 'using nvim instead'
2024-06-07 07:55:24 +02:00
/usr/bin/env nvim " $@ "
2023-10-19 08:51:32 +02:00
}
else
vim( ) {
echo 'nvim not found'
2024-06-07 07:55:24 +02:00
/usr/bin/env vim " $@ "
2023-10-19 08:51:32 +02:00
}
fi
2022-03-17 14:00:15 +01:00
2024-07-28 10:19:38 +02:00
# 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 "
}
2024-08-04 13:32:38 +02:00
# Lazyish ACL aware ls
2024-08-08 08:37:12 +02:00
unalias ls > /dev/null 2>& 1
2024-08-04 13:23:25 +02:00
ls( ) {
env ls --all --color= auto --human-readable " $@ "
2024-08-04 13:32:38 +02:00
if hash getfacl 2> /dev/null; then
if [ [ -d " $@ " || -f " $@ " ] ] ; then
printf "\n"
getfacl --absolute-names --skip-base " $@ "
fi
fi
2024-08-04 13:23:25 +02:00
}
2024-08-08 08:37:12 +02:00
unalias ll > /dev/null 2>& 1
2024-08-04 13:41:18 +02:00
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
}
2024-08-04 13:23:25 +02:00
2011-10-29 09:50:56 +02:00
# Source files for miscannellious modifications.
2019-08-09 18:47:27 +02:00
# acme.sh
if [ -f ~/.acme.sh/acme.sh.env ] ; then
2023-02-15 12:29:55 +01:00
source ~/.acme.sh/acme.sh.env
2019-08-09 18:47:27 +02:00
fi
2011-10-29 09:50:56 +02:00
# .custom
if [ -f ~/.custom ] ; then
2023-02-15 12:29:55 +01:00
source ~/.custom
2014-07-17 15:05:42 +02:00
fi
2011-10-02 16:05:17 +02:00
2011-10-29 09:50:56 +02:00
# .zsh_custom
2011-10-02 16:22:09 +02:00
if [ -f ~/.zsh_custom ] ; then
2023-02-15 12:29:55 +01:00
source ~/.zsh_custom
2014-07-17 15:05:42 +02:00
fi
2012-07-14 19:46:08 +02:00
# Warnings
if [ -f ~/.warnings ] ; then
2023-02-15 12:29:55 +01:00
source ~/.warnings
2014-07-17 15:05:42 +02:00
fi
2024-07-24 11:28:03 +02:00
# vim: filetype=zsh