Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
#!/bin/zsh
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ________ ________ ___ ___ _______ ___ ___ ║
# ║ |\_____ \|\ ____\|\ \|\ \|\ ___ \ |\ \ |\ \ ║
# ║ \|___/ /\ \ \___|\ \ \\\ \ \ __/|\ \ \ \ \ \ ║
# ║ / / /\ \_____ \ \ __ \ \ \_|/_\ \ \ \ \ \ ║
# ║ / /_/__\|____|\ \ \ \ \ \ \ \_|\ \ \ \____\ \ \____ ║
# ║ |\________\____\_\ \ \__\ \__\ \_______\ \_______\ \_______\ ║
# ║ \|_______|\_________\|__|\|__|\|_______|\|_______|\|_______| ║
# ║ \|_________| ║
# ║ ║
# ║ xn--gckvb8fzb.com * github.com/mrusme * marius@xn--gckvb8fzb.com ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════════════╝
# zmodload zsh/zprof
export ZSH_TMUX_AUTOSTART=true
[[ "$USER" == "root" ]] && export ZSH_TMUX_AUTOSTART=false
type /usr/local/bin/zsh > /dev/null \
&& export SHELL=/usr/local/bin/zsh
export OS=$(uname)
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_DOWNLOAD_DIR="$HOME/downloads"
export XDG_DESKTOP_DIR="$HOME/desktop"
export ICONS_PATH="$HOME/projects/github/arcticons/icons/white"
# if [[ "$(lspci | grep -i geforce)" ]]
# then
# export WLR_NO_HARDWARE_CURSORS=1
# fi
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Tmux Magic (via SSH) ║
# ╚════════════════════════════════════════════════════════════════════════════╝
type tmux > /dev/null \
&& [[ -n $SSH_CONNECTION ]] \
&& [[ -z $TMUX ]] \
&& [[ "$USER" != "root" ]] \
&& tmux new-session -A -s ssh && exit
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ General config ║
# ╚════════════════════════════════════════════════════════════════════════════╝
export HISTCONTROL=ignoredups:ignorespace
export HISTSIZE=100000
export HISTFILESIZE=200000
export SAVEHIST=$HISTSIZE
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
# export TERM=xterm-16color
export TERM=xterm-256color
export COLUMNS=80
export EDITOR=vim
type nvim > /dev/null \
&& export EDITOR=nvim
if [[ -n $SSH_CONNECTION ]]; then
export BROWSER=w3m
else
if [[ "$OS" = "Linux" ]]
then
export BROWSER=/usr/local/bin/browser
elif [[ "$OS" = "Darwin" ]]
then
export BROWSER=open
fi
fi
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Programs & tools ║
# ╚════════════════════════════════════════════════════════════════════════════╝
export SSH_KEY_PATH="$HOME/.ssh/id_ed25519"
# Pass
export PASSWORD_STORE_DIR="$HOME/cloud/.password-store"
# Enable Erlang/IEx shell history
export ERL_AFLAGS="-kernel shell_history enabled"
# IPFS
export IPFS_PATH="$HOME/.ipfs"
# Firefox
#export GDK_BACKEND="wayland"
export MOZ_ENABLE_WAYLAND=1
export MOZ_USE_XINPUT2="1"
# Qt
export QT_STYLE_OVERRIDE=kvantum
# https://github.com/oz/tz/
export TZ_LIST="Pacific/Honolulu;America/Panama;\
America/New_York;Etc/UTC;Europe/Berlin;Asia/Bangkok;\
Asia/Tokyo;Australia/Melbourne;Pacific/Auckland;"
# https://notmuchmail.org/manpages/notmuch-1/
export NOTMUCH_PROFILE=01
# https://github.com/mrusme/zeit
export ZEIT_DB="$HOME/cloud/.zeit.db"
# https://github.com/mrusme/geld
export GELD_DB="$HOME/cloud/.geld.db"
# https://github.com/mrusme/addrb
export ADDRB_DB="$HOME/.cache/addrb.db"
export ADDRB_TEMPLATE="$HOME/.config/addrb.tmpl"
# Import color scheme via wal
#[[ "$OS" = "Linux" ]] \
#&& type wal > /dev/null && (wal -r &)
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ $PATH ║
# ╚════════════════════════════════════════════════════════════════════════════╝
[[ "$OS" = "Darwin" ]] \
&& eval "$(/usr/libexec/path_helper -s)"
# /usr/local/* (Homebrew, etc)
[[ "$OS" = "Darwin" ]] \
&& export PATH="/usr/local/bin:/usr/local/sbin:\
/usr/local/opt/binutils/bin:$PATH"\
&& export MANPATH="/usr/local/man:$MANPATH"
# Cargo (Rust)
[[ -d "$HOME/.cargo/bin" ]] \
&& export PATH="$HOME/.cargo/bin:$PATH"
[[ -e "$HOME/.cargo/env" ]] \
&& source "$HOME/.cargo/env"
# Go
[[ "$OS" = "Darwin" ]] \
&& export GOROOT="/usr/local/opt/go/libexec"
go env -w GOPATH="$HOME/.go"
export PATH=$HOME/.go/bin:$PATH
export GOPROXY=direct
# Python virtualenv
export VIRTUALENVWRAPPER_PYTHON="$(which python3)"
export WORKON_HOME="$HOME/.virtualenvs"
function activate.virtualenv {
type virtualenvwrapper_lazy.sh > /dev/null \
&& source "$(which virtualenvwrapper_lazy.sh)" \
&& workon | grep local > /dev/null \
&& workon local \
&& printf "Activated local.\n" \
|| printf "Could not load virtualenvwrapper.\n"
}
export PYTHON_MAJOR_MINOR="$(python3 \
--version | sed -nr 's/.*([0-9]+\.[0-9]+)\..*/\1/p')"
[[ -d "$HOME/Library/Python/$PYTHON_MAJOR_MINOR/bin" ]] \
&& export PATH="$HOME/Library/Python/$PYTHON_MAJOR_MINOR/bin:$PATH"
# Ruby
[[ "$OS" = "Darwin" ]] \
&& export PATH="/usr/local/Cellar/ruby/$(ls -1 /usr/local/Cellar/ruby/ \
| sort \
| tail -n 1)/bin:$PATH"
# Rubygems
type gem > /dev/null \
&& export PATH="$(gem env \
| grep "EXECUTABLE DIRECTORY" \
| awk -F ': ' '{ print $2 }'):$PATH" \
&& export PATH="$(gem env \
| grep "USER INSTALLATION DIRECTORY" \
| awk -F ': ' '{ print $2 }')/bin:$PATH"
# NPM
export NPM_PACKAGES="${HOME}/.local/lib64/node_modules"
export PATH="$PATH:$NPM_PACKAGES/bin"
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"
# Wayland
if [[ "$OS" = "Linux" ]]
then
alias sway-launch='dbus-launch --exit-with-session sway'
if test -z "${XDG_RUNTIME_DIR}"
then
export XDG_RUNTIME_DIR=/tmp/${UID}-runtime-dir
if ! test -d "${XDG_RUNTIME_DIR}"
then
mkdir "${XDG_RUNTIME_DIR}"
chmod 0700 "${XDG_RUNTIME_DIR}"
fi
fi
GTK_THEME=$(gsettings get org.gnome.desktop.interface gtk-theme)
export GTK2_RC_FILES="$HOME/.themes/$GTK_THEME/gtk-2.0/gtkrc"
fi
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ OMZ ║
# ╚════════════════════════════════════════════════════════════════════════════╝
export ZSH="$HOME/.oh-my-zsh"
# [[ -e $ZSH ]] || \
# ([[ "$USER" != "root" ]] && sh -c "$(curl -fsSL \
# https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)")
ZSH_THEME="geometry-zsh/geometry"
[[ "$USER" == "root" ]] && GEOMETRY_SEPARATOR=" root"
CASE_SENSITIVE="true"
DISABLE_AUTO_UPDATE="false"
[[ "$USER" == "root" ]] \
&& DISABLE_AUTO_UPDATE="true"
UPDATE_ZSH_DAYS=10
DISABLE_LS_COLORS="false"
DISABLE_AUTO_TITLE="false"
ENABLE_CORRECTION="false"
COMPLETION_WAITING_DOTS="false"
DISABLE_UNTRACKED_FILES_DIRTY="false"
ZSH_AUTOSUGGESTIONS="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}\
/plugins/zsh-autosuggestions"
ZSH_COMPDUMP=$XDG_CACHE_HOME/.zcompdump-$HOST
[[ "$OS" = "Darwin" ]] \
&& plugins=( \
docker encode64 extract git git-flow git-extras gpg-agent history ssh-agent \
1password urltools ripgrep rsync ipfs web-search isodate \
golang rust mix gh \
zsh-autosuggestions mosh fzf terraform taskwarrior thefuck fasd \
brew tmux macos)
[[ "$OS" = "Linux" && "$USER" != "root" ]] \
&& plugins=(\
docker encode64 extract git git-flow git-extras gpg-agent history ssh-agent \
1password urltools ripgrep rsync ipfs web-search isodate \
golang rust mix gh \
zsh-autosuggestions mosh fzf terraform taskwarrior thefuck fasd \
pass)
[[ -e "$ZSH/oh-my-zsh.sh" ]] && source "$ZSH/oh-my-zsh.sh"
fpath=(
/usr/local/share/zsh-completions
/usr/local/share/zsh/site-functions
$fpath
)
ZSH_THEME_TERM_TITLE_IDLE='zsh %n@%m:%~'
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Aliases ║
# ╚════════════════════════════════════════════════════════════════════════════╝
# https://github.com/ajeetdsouza/zoxide
type zoxide > /dev/null \
&& eval "$(zoxide init --cmd cd zsh)"
type bat > /dev/null \
&& alias cat=bat
type exa > /dev/null \
&& unalias ls la ll l lsa &> /dev/null \
&& alias ls='exa --time-style=long-iso --git --binary -lg' \
&& alias la='exa --time-style=long-iso --git --icons --binary -la' \
&& alias ll='exa --time-style=long-iso --git --icons --octal-permissions --binary --changed -lahHgnuU' \
&& alias l='exa --time-style=long-iso --git --icons --binary -l --no-time' \
&& alias lls='ls -s modified'
type btm > /dev/null \
&& alias top='btm'
type neomutt > /dev/null \
&& alias mutt=neomutt
type nvim > /dev/null \
&& alias vi=nvim \
&& alias vim=nvim
type fzf > /dev/null \
&& alias preview='fzf --preview="bat {} --color=always"'
type eva > /dev/null \
&& alias calc='eva'
type gron > /dev/null \
&& alias json='gron'
type hexyl > /dev/null \
&& alias hex='hexyl'
type hyperfine > /dev/null \
&& alias benchmark='hyperfine'
type irssi > /dev/null \
&& alias irc='irssi'
type xdg-open > /dev/null \
&& alias open='xdg-open'
type taskwarrior-tui > /dev/null \
&& alias todo='taskwarrior-tui'
alias fucking=sudo
alias my-ip="curl http://ipecho.net/plain; echo"
alias jrnl='cd $HOME/[Pp]rojects/@mrusme/xn--gckvb8fzb.com/content/'
alias bookmarks='vim $HOME/[Pp]rojects/@mrusme/xn--gckvb8fzb.com/content/bookmarks/index.md'
alias notes='cd $HOME/[Cc]loud/notes/'
alias cheatsheet.vim='vim $HOME/[Cc]loud/notes/tools/vim.md'
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Bound keys ║
# ╚════════════════════════════════════════════════════════════════════════════╝
[[ "$OS" = "Darwin" ]] \
&& bindkey "\e[1;3C" forward-word \
&& bindkey "\e[1;3D" backward-word
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ __ __ __ ║
# ║ / // /__ / /__ ___ _______ ║
# ║ / _ / -_) / _ \/ -_) __(_-< ║
# ║ /_//_/\__/_/ .__/\__/_/ /___/ ║
# ║ /_/ ║
# ╚════════════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Mosh/SSH wrapper ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function ssh {
if [ "$2" = "" ]
then
conn="$1"
sshhost=$(printf "%s" "$conn" | cut -d '@' -f2)
if rg -U -i "^#.*Features:.*mosh.*\nHost $sshhost" "$HOME/.ssh/config" > /dev/null
then
printf "connecting with mosh ...\n"
command mosh $conn
else
printf "connecting with ssh ...\n"
command ssh $conn
fi
else
printf "connecting with ssh ...\n"
command ssh $@
fi
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Poor-man's aptitude ║
# ╚════════════════════════════════════════════════════════════════════════════╝
if [ "$OS" = "Darwin" ]
then
function aptitude {
if [ -z "$1" ]; then
printf "Usage: aptitude <action> [options] ...\n"
else
case $1 in
install) brew install "${@:2}";;
remove) brew uninstall "${@:2}";;
purge) brew uninstall "${@:2}"; brew cleanup;;
update) brew update "${@:2}";;
upgrade) brew upgrade "${@:2}";;
safe-upgrade)brew upgrade "${@:2}";;
full-upgrade)brew upgrade "${@:2}";;
search) brew search "${@:2}";;
show) brew info "${@:2}";;
clean) brew cleanup "${@:2}";;
reinstall) brew uninstall "${@:2}"; brew cleanup; brew install "${@:2}";;
*) printf "aptitude: '$1' - unknown action\n" ;;
esac
fi
}
elif [[ "$OS" = "Linux" && "$(uname -a | grep -i gentoo)" ]]
then
function aptitude {
if [ -z "$1" ]; then
printf "Usage: aptitude <action> [options] ...\n"
else
case $1 in
install) emerge -av --keep-going=y "${@:2}";;
remove) emerge -cav "${@:2}";;
purge) emerge -Cav "${@:2}";;
update) emerge --sync "${@:2}";;
upgrade) emerge --ask --update --deep --changed-use --verbose-conflicts --keep-going=y "${@[2]:-@world}";;
safe-upgrade)emerge -avu --keep-going=y "${@[2]:-@world}";;
full-upgrade)emerge -avuND --keep-going=y --with-bdeps=y "${@[2]:-@world}";;
search) emerge -s "${@:2}";;
show) equery meta "${@:2}";;
clean) emerge -avc "${@:2}";;
reinstall) emerge -ave "${@:2}";;
*) printf "aptitude: '$1' - unknown action\n" ;;
esac
fi
}
elif [[ "$OS" = "Linux" && "$(type pacman > /dev/null)" ]]
then
function aptitude {
if [ -z "$1" ]; then
printf "Usage: aptitude <action> [options] ...\n"
else
case $1 in
install) pacman -S "${@:2}";;
remove) pacman -R "${@:2}";;
purge) pacman -Rs "${@:2}";;
update) pacman -Syy "${@:2}";;
upgrade) pacman -Syu "${@:2}";;
safe-upgrade)pacman -Syu "${@:2}";;
full-upgrade)pacman -Syu "${@:2}";;
search) pacman -Ss "${@:2}";;
show) pacman -Si "${@:2}";;
clean) pacman -Scc "${@:2}";;
reinstall) pacman -S "${@:2}";;
*) printf "aptitude: '$1' - unknown action\n" ;;
esac
fi
}
elif [[ "$OS" = "OpenBSD" ]]
then
function aptitude {
if [ -z "$1" ]; then
printf "Usage: aptitude <action> [options] ...\n"
else
case $1 in
install) pkg_add "${@:2}";;
remove) pkg_delete "${@:2}";;
purge) pkg_delete -a "${@:2}";;
update) pkg_add -Uuin "${@:2}";;
upgrade) pkg_add -Uui "${@:2}";;
safe-upgrade)sysupgrade;;
full-upgrade)sysupgrade;;
search) pkg_info -Q "${@:2}";;
show) pkg_info "${@:2}";;
clean) pkg_check "${@:2}";;
reinstall) pkg_add -Uui "${@:2}";;
*) printf "aptitude: '$1' - unknown action\n" ;;
esac
fi
}
fi
if [[ "$OS" = "Darwin" ]] \
|| [[ "$OS" = "OpenBSD" ]] \
|| [[ "$OS" = "Linux" && "$(uname -a | grep -i gentoo)" ]] \
|| type pacman > /dev/null
then
_aptitude()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "install remove purge update upgrade \
safe-upgrade full-upgrade search show \
clean reinstall" -- $cur) )
}
fi
alias apt='aptitude'
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ OpenSSL ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function openssl-view-certificate () {
openssl x509 -text -noout -in "${1}"
}
function openssl-view-csr () {
openssl req -text -noout -verify -in "${1}"
}
function openssl-view-key () {
openssl rsa -check -in "${1}"
}
function openssl-view-pkcs12 () {
openssl pkcs12 -info -in "${1}"
}
function openssl-client () {
openssl s_client -status -connect "${1}":443
}
# Convert PEM private key, PEM certificate and PEM CA certificate
# (used by nginx, Apache, and other openssl apps) to a PKCS12 file
# (typically for use with Windows or Tomcat)
function openssl-convert-pem-to-p12 () {
openssl pkcs12 -export -inkey "${1}" -in "${2}" -certfile "${3}" -out "${4}"
}
# Convert a PKCS12 file to PEM
function openssl-convert-p12-to-pem () {
openssl pkcs12 -nodes -in "${1}" -out "${2}"
}
# Check the modulus of a certificate (to see if it matches a key)
function openssl-check-certificate-modulus {
openssl x509 -noout -modulus -in "${1}" | shasum -a 256
}
# Check the modulus of a key (to see if it matches a certificate)
function openssl-check-key-modulus {
openssl rsa -noout -modulus -in "${1}" | shasum -a 256
}
# Check the modulus of a certificate request
function openssl-check-key-modulus {
openssl req -noout -modulus -in "${1}" | shasum -a 256
}
# Encrypt a file (because zip crypto isn't secure)
function openssl-encrypt () {
openssl aes-256-cbc -in "${1}" -out "${2}"
}
# Decrypt a file
function openssl-decrypt () {
openssl aes-256-cbc -d -in "${1}" -out "${2}"
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ pushover ║
# ╚════════════════════════════════════════════════════════════════════════════╝
__pushover_usage() {
printf "pushover <options> <message>\n"
printf " -c <callback>\n"
printf " -d <device>\n"
printf " -D <timestamp>\n"
printf " -e <expire>\n"
printf " -p <priority>\n"
printf " -r <retry>\n"
printf " -t <title>\n"
printf " -T <TOKEN> (required if not in 'pass show pushover/token')\n"
printf " -s <sound>\n"
printf " -u <url>\n"
printf " -U <USER> (required if not in 'pass show pushover/user')\n"
printf " -a <url_title>\n"
return 1
}
__pushover_opt_field() {
field=$1
shift
value="${*}"
if [ -n "${value}" ]; then
printf "-F \"${field}=${value}\"\n"
fi
}
__pushover_send_message() {
local device="${1:-}"
curl_cmd="\"${CURL}\" -s -S \
${CURL_OPTS} \
-F \"token=${TOKEN}\" \
-F \"user=${USER}\" \
-F \"message=${message}\" \
$(__pushover_opt_field device "${device}") \
$(__pushover_opt_field callback "${callback}") \
$(__pushover_opt_field timestamp "${timestamp}") \
$(__pushover_opt_field priority "${priority}") \
$(__pushover_opt_field retry "${retry}") \
$(__pushover_opt_field expire "${expire}") \
$(__pushover_opt_field title "${title}") \
$(__pushover_opt_field sound "${sound}") \
$(__pushover_opt_field url "${url}") \
$(__pushover_opt_field url_title "${url_title}") \
\"${PUSHOVER_URL}\""
response="$(eval "${curl_cmd}")"
printf "$response\n"
# TODO: Parse response
r="${?}"
if [ "${r}" -ne 0 ]; then
printf "%s: Failed to send message\n" "${0}" >&2
fi
return "${r}"
}
function pushover() {
local CURL="$(which curl)"
local PUSHOVER_URL="https://api.pushover.net/1/messages.json"
local TOKEN=$(pass show pushover/token)
local USER=$(pass show pushover/user)
local CURL_OPTS=""
local device_aliases=""
local devices="${devices} ${device}"
local optstring="c:d:D:e:f:p:r:t:T:s:u:U:a:h"
OPTIND=1
while getopts ${optstring} c
do
case ${c} in
c)
callback="${OPTARG}"
;;
d)
devices="${devices} ${OPTARG}"
;;
D)
timestamp="${OPTARG}"
;;
e)
expire="${OPTARG}"
;;
p)
priority="${OPTARG}"
;;
r)
retry="${OPTARG}"
;;
t)
title="${OPTARG}"
;;
k)
TOKEN="${OPTARG}"
;;
s)
sound="${OPTARG}"
;;
u)
url="${OPTARG}"
;;
U)
USER="${OPTARG}"
;;
a)
url_title="${OPTARG}"
;;
[h\?])
__pushover_usage
return 1
;;
esac
done
shift $((OPTIND-1))
if [ "$#" -lt 1 ]; then
__pushover_usage
return 1
fi
message="$*"
if [ ! -x "${CURL}" ]; then
printf "CURL is unset, empty, or does not point to curl executable.\n \
This script requires curl!\n" >&2
return 1
fi
devices="$(printf "${devices}" | xargs -n1 | sort -u | uniq)\n"
if [ -z "${devices}" ]; then
__pushover_send_message
r=${?}
else
for device in ${devices}; do
__pushover_send_message "${device}"
r=${?}
if [ "${r}" -ne 0 ]; then
break;
fi
done
fi
return "${r}"
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ update-tools ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function update-tools() {
printf "Updating Rust tools ...\n"
cargo install-update -a
printf "\nUpdating Go tools ...\n"
/bin/ls -1 ~/.go/bin/ \
| while read bin; do go version -m ~/.go/bin/$bin \
| grep '^[[:space:]]path' \
| awk '{ print $2 }' \
| grep '^github.com' \
| sort \
| uniq \
| xargs -I{} go install {}@latest; done
printf "\nUpdating NPM tools ...\n"
npm update -g
printf "\nUpdating gh extensions ...\n"
gh extension upgrade --all
printf "\nTools updated"
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ terminal-colors ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function terminal-colors() {
if [[ $1 == "dark" ]]
then
sed -i=.previous 's/\*light$/\*dark/g' "$XDG_CONFIG_HOME/alacritty/alacritty.yml"
else
sed -i=.previous 's/\*dark$/\*light/g' "$XDG_CONFIG_HOME/alacritty/alacritty.yml"
fi
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Custom git helpers ║
# ╚════════════════════════════════════════════════════════════════════════════╝
alias git-crypt-add-myself="git-crypt add-gpg-user \
4D3899AF73E7F5FE9B39C822272ED814BF63261F"
alias gpa='git push all "$(git_current_branch)"'
# git tag delete
gtd() {
git tag -d "$1"
git remote | while read remote; do git push --delete "$remote" "$1"; done
}
function git-add-all-remote() {
if git remote | grep -q '^all$'
then
printf "Remote 'all' already exists!\n"
return 1
else
git remote | while read -r remote
do
git config --add remote.all.url "$(git remote get-url --all $remote)"
printf "Remote $remote added to 'all'\n"
done
return 0
fi
}
function git-find-modified-repos() {
find ./ -type d -name '.git' | while read -r dir
do
repo=$(dirname "$dir")
repostatus=$(git -C "$repo" status -s)
if [[ -n "$repostatus" ]]
then
printf "$repo\n"
fi
done
}
function ghcoi() {
if [ "$1" = "" ]
then
printf "usage: %s <issue number>\n" "$0"
exit 1
fi
git checkout -b "$1-$(gh issue view $1 --json title \
| jq --raw-output '.title' \
| iconv -t ascii//TRANSLIT \
| sed -E 's/[^a-zA-Z0-9]+/-/g' \
| sed -E 's/^-+|-+$//g' \
| tr A-Z a-z)"
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Offline Wikipedia (https://xn--gckvb8fzb.com/lets-take-wikipedia-offline) ║
# ╚════════════════════════════════════════════════════════════════════════════╝
export WIKIPEDIA_INDEX_ID="wikipedia"
export WIKIPEDIA_METASTORE_URI="file:///home/mrus/projects/@mrusme/ulpia/wikipedia"
export DISABLE_QUICKWIT_TELEMETRY=1
function wikipedia() {
search="$*"
query="title:\"$search\""
json=$(quickwit index search \
--index-id "$WIKIPEDIA_INDEX_ID" \
--metastore-uri "$WIKIPEDIA_METASTORE_URI" \
--query "$query" \
)
numHits=$(printf '%s' "$json" | jq '.numHits')
if [[ $numHits == 0 ]]
then
printf "Nothing found, sorry.\n"
return 1
fi
selection=$(printf '%s' "$json" \
| jq \
--raw-output \
'.hits[].title[0]' \
| /bin/cat -n \
| fzf \
--no-multi \
-0 \
-q "$search" \
--with-nth 2.. \
)
if [[ $? == 130 ]]
then
return 2
fi
index=$(echo "$selection" \
| awk '{ print $1-1 }' \
)
if [[ -n "$index" ]]
then
printf '%s' "$json" \
| jq \
--raw-output \
".hits[$index].section_texts | join(\"\n\n\n\")" \
| pandoc \
-f mediawiki \
-t markdown_strict \
| glow - -p
else
printf "Err?\n"
return 3
fi
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Online tools ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function jitsi-link() {
url=$(printf "https://meet.jit.si/%s" "$(uuidgen)")
printf "%s" "$url" | wl-copy
printf "%s\n" "$url"
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Math functions ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function calc-x-percent-of-y() {
eva "($1 / 100) * $2" | tr -d ' '
}
function calc-percentage-x-of-y() {
eva "($1 / $2) * 100" | tr -d ' '
}
function calc-percentage-change-x-to-y() {
eva "(($2 - $1) / $1) * 100" | tr -d ' '
}
function convert-fahrenheit-to-celsius() {
eva "($1 - 32) * (5/9)" | tr -d ' '
}
function convert-celsius-to-fahrenheit() {
eva "($1 * (9/5)) + 32" | tr -d ' '
}
function convert-in-to-cm() {
eva "$1 * 2.54" | tr -d ' '
}
function convert-cm-to-in() {
eva "$1 / 2.54" | tr -d ' '
}
function convert-ft-to-cm() {
eva "$1 * 30.48" | tr -d ' '
}
function convert-cm-to-ft() {
eva "$1 / 30.48" | tr -d ' '
}
function convert-ft-in-to-m() {
eva "$1 * 30.48 + $2 * 2.54" | tr -d ' '
}
function convert-cm-to-ft-in() {
ft=$(eva "floor($1 / 2.54) / 12" | tr -d ' ')
in=$(eva "($1 / 2.54) - 12 * $ft" | tr -d ' ')
printf "$ft ft $in in\n"
}
function convert-kn-to-kmh() {
eva "$1 * 1.852" | tr -d ' '
}
function convert-kmh-to-kn() {
eva "$1 / 1.852" | tr -d ' '
}
function convert-mph-to-kmh() {
eva "$1 * 1.609344" | tr -d ' '
}
function convert-kmh-to-mph() {
eva "$1 / 1.609344" | tr -d ' '
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Audio & video ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function video-to-gif() {
ffmpeg \
-i "$1" \
-vf \
"fps=10,scale=800:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
-loop 0 \
"$2"
}
function rip() {
youtube-dl \
-f bestaudio \
--extract-audio \
--audio-format mp3 \
--audio-quality 0 \
--yes-playlist \
--add-metadata \
"$1"
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ addrb ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function addrb() {
export CARDDAV_USERNAME=$(pass show dav/username)
export CARDDAV_PASSWORD=$(pass show dav/password)
export CARDDAV_ENDPOINT=$(pass show dav/endpoint)
command addrb $@
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ planor ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function planor() {
export VULTR_API_KEY=$(pass show vultr/token)
export RENDER_API_TOKEN=$(pass show render/token)
export FLEEK_API_TOKEN=$(pass show fleek/token)
export FLEEK_TEAM_ID=$(pass show fleek/team)
command planor $@
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ conclusive ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function conclusive() {
export PLAUSIBLE_TOKEN=$(pass show plausible/token)
command conclusive $@
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ wtfutil ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function wtfutil() {
export WTF_GITHUB_TOKEN=$(pass show wtfutil/token)
command wtfutil $@
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ gh ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function gh() {
export GITHUB_TOKEN=$(pass show github/token)
command gh $@
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ dotfiles-update-remote ║
# ╚════════════════════════════════════════════════════════════════════════════╝
[[ "$OS" = "Darwin" ]] \
&& export DOTFILES="$HOME/Projects/@mrusme/dotfiles"
[[ "$OS" = "Linux" ]] \
&& export DOTFILES="$HOME/projects/@mrusme/dotfiles"
# [[ "$OS" = "Darwin" ]] \
# && subldir=$HOME/Library/Application\ Support/Sublime\ Text\ 3
# [[ "$OS" = "Linux" ]] \
# && subldir=$XDG_CONFIG_HOME/sublime-text
function dotfiles-update-remote() {
cp "$HOME/.zshrc" "$DOTFILES/.zshrc"
cp "$HOME/.tmux.conf" "$DOTFILES/.tmux.conf"
cp "$HOME/.tmux.cheatsheet" "$DOTFILES/.tmux.cheatsheet"
cp "$HOME/.motd" "$DOTFILES/.motd"
cp "$HOME/.gitconfig" "$DOTFILES/.gitconfig"
cp "$HOME/.mbsyncrc" "$DOTFILES/.mbsyncrc"
cp "$HOME/.wallpaper" "$DOTFILES/.wallpaper"
cp "$HOME/.ssh/config" "$DOTFILES/ssh/config"
cp -R "$HOME/.irssi/"* "$DOTFILES/irssi/"
cp "$HOME/.mozilla/firefox/"*".default-release/chrome/userChrome.css"\
"$DOTFILES/.mozilla/firefox/default/chrome/userChrome.css"
cp "$XDG_CONFIG_HOME/alacritty/alacritty.yml"\
"$DOTFILES/alacritty/alacritty.yml"
cp "$XDG_CONFIG_HOME/neomutt/neomuttrc" "$DOTFILES/neomutt/neomuttrc"
cp "$XDG_CONFIG_HOME/neomutt/accounts/"* "$DOTFILES/neomutt/accounts/"
cp "$XDG_CONFIG_HOME/nvim/init.vim" "$DOTFILES/nvim/init.vim"
cp "$XDG_CONFIG_HOME/nvim/colors/"*.vim "$DOTFILES/nvim/colors/"
cp "$XDG_CONFIG_HOME/nvim/autoload/lightline/colorscheme/"*.vim\
"$DOTFILES/nvim/autoload/lightline/colorscheme/"
cp "$XDG_CONFIG_HOME/lf/"* "$DOTFILES/lf/"
cp "$XDG_CONFIG_HOME/wtf/config.yml" "$DOTFILES/wtf/config.yml"
# Phasing out Sublime Text as I'm not using it anymore
#
# cp $subldir/Packages/User/Package\ Control.sublime-settings\
# "$DOTFILES/st3/Package Control.sublime-settings"
# cp $subldir/Packages/User/Preferences.sublime-settings\
# "$DOTFILES/st3/Preferences.sublime-settings"
# cp $subldir/Packages/User/LSP.sublime-settings\
# "$DOTFILES/st3/LSP.sublime-settings"
# cp $subldir/Packages/User/vap0r-*.tmTheme\
# "$DOTFILES/st3/"
if [ "$OS" = "Darwin" ]
then
brew ls --formula -1 --full-name > "$DOTFILES/brew/ls_-1"
brew ls --cask -1 --full-name > "$DOTFILES/brew/cask_ls_-1"
fi
if [ "$OS" = "Linux" ]
then
/usr/bin/find /usr/local/bin -type f -exec sh -c '
case $( file -bi "$1" ) in (*/x-shellscript*) exit 0; esac
exit 1' sh {} \; -print | while read -r scriptfile
do
cp "$scriptfile" "$DOTFILES/usr/local/bin/"
done
cp "$XDG_CONFIG_HOME/dunst/dunstrc" "$DOTFILES/dunst/dunstrc"
cp "$XDG_CONFIG_HOME/mpd/mpd.conf" "$DOTFILES/mpd/mpd.conf"
cp "$XDG_CONFIG_HOME/ncmpcpp/config" "$DOTFILES/ncmpcpp/config"
cp "$XDG_CONFIG_HOME/sway/config" "$DOTFILES/sway/config"
cp "$XDG_CONFIG_HOME/swaylock/config" "$DOTFILES/swaylock/config"
cp "$XDG_CONFIG_HOME/swaynag/config" "$DOTFILES/swaynag/config"
cp "$XDG_CONFIG_HOME/task/taskrc" "$DOTFILES/task/taskrc"
cp "$XDG_CONFIG_HOME/waybar/"* "$DOTFILES/waybar/"
cp "$XDG_CONFIG_HOME/wofi/"* "$DOTFILES/wofi/"
cp "$HOME/.local/share/applications/browser.desktop" "$DOTFILES/local/share/applications/browser.desktop"
fi
cargo install --list > "$DOTFILES/cargo/install_--list"
npm list -g --depth=0 > "$DOTFILES/npm/list_-g_--depth_0"
/bin/ls -1 ~/.go/bin/ \
| while read bin; \
do go version -m ~/.go/bin/$bin \
| grep '^[[:space:]]path' \
| awk '{ print $2 }' \
| grep '^github.com' \
| sort \
| uniq;\
done > "$DOTFILES/go/list_github.com"
gh extension list > "$DOTFILES/gh_extension_list"
git -C "$DOTFILES" commit -a -S
return 0
}
function dotfiles-update-local() {
printf "are you sure? (y/n) "
read -r confirmation
[[ $confirmation != "y" ]] && return 1
cp "$DOTFILES/.zshrc" "$HOME/.zshrc"
cp "$DOTFILES/.tmux.conf" "$HOME/.tmux.conf"
cp "$DOTFILES/.tmux.cheatsheet" "$HOME/.tmux.cheatsheet"
cp "$DOTFILES/.motd" "$HOME/.motd"
cp "$DOTFILES/.gitconfig" "$HOME/.gitconfig"
cp "$DOTFILES/.mbsyncrc" "$HOME/.mbsyncrc"
cp "$DOTFILES/.wallpaper" "$HOME/.wallpaper"
cp "$DOTFILES/ssh/config" "$HOME/.ssh/config"
cp -R "$DOTFILES/irssi/"* "$HOME/.irssi/"
mkdir -p "$XDG_CONFIG_HOME/alacritty"
cp "$DOTFILES/alacritty/alacritty.yml"\
"$XDG_CONFIG_HOME/alacritty/alacritty.yml"
mkdir -p "$XDG_CONFIG_HOME/neomutt/accounts"
cp "$DOTFILES/neomutt/neomuttrc" "$XDG_CONFIG_HOME/neomutt/neomuttrc"
mkdir -p "$XDG_CONFIG_HOME/nvim/colors"
mkdir -p "$XDG_CONFIG_HOME/nvim/autoload/lightline/colorscheme"
cp "$DOTFILES/nvim/init.vim" "$XDG_CONFIG_HOME/nvim/init.vim"
cp "$DOTFILES/nvim/colors/"*.vim "$XDG_CONFIG_HOME/nvim/colors/"
cp "$DOTFILES/nvim/autoload/lightline/colorscheme/"*.vim\
"$XDG_CONFIG_HOME/nvim/autoload/lightline/colorscheme/"
mkdir -p "$XDG_CONFIG_HOME/lf"
cp "$DOTFILES/lf/"* "$XDG_CONFIG_HOME/lf/"
mkdir -p "$XDG_CONFIG_HOME/wtf"
cp "$DOTFILES/wtf/config.yml" "$XDG_CONFIG_HOME/wtf/config.yml"
# Phasing out Sublime Text as I'm not using it anymore
#
# cp "$DOTFILES/st3/Package Control.sublime-settings"\
# $subldir/Packages/User/Package\ Control.sublime-settings
# cp "$DOTFILES/st3/Preferences.sublime-settings"\
# $subldir/Packages/User/Preferences.sublime-settings
# cp "$DOTFILES/st3/LSP.sublime-settings"\
# $subldir/Packages/User/LSP.sublime-settings
# cp "$DOTFILES/st3/vap0r-*.tmTheme"
# $subldir/Packages/User/
if [ "$OS" = "Linux" ]
then
cp "$DOTFILES/usr/local/bin/"* /usr/local/bin/
mkdir -p "$XDG_CONFIG_HOME/dunst"
cp "$DOTFILES/dunst/dunstrc" "$XDG_CONFIG_HOME/dunst/dunstrc"
mkdir -p "$XDG_CONFIG_HOME/mpd"
cp "$DOTFILES/mpd/mpd.conf" "$XDG_CONFIG_HOME/mpd/mpd.conf"
mkdir -p "$XDG_CONFIG_HOME/ncmpcpp"
cp "$DOTFILES/ncmpcpp/config" "$XDG_CONFIG_HOME/ncmpcpp/config"
mkdir -p "$XDG_CONFIG_HOME/sway"
cp "$DOTFILES/sway/config" "$XDG_CONFIG_HOME/sway/config"
mkdir -p "$XDG_CONFIG_HOME/swaylock"
cp "$DOTFILES/swaylock/config" "$XDG_CONFIG_HOME/swaylock/config"
mkdir -p "$XDG_CONFIG_HOME/swaynag"
cp "$DOTFILES/swaynag/config" "$XDG_CONFIG_HOME/swaynag/config"
mkdir -p "$XDG_CONFIG_HOME/task"
cp "$DOTFILES/task/taskrc" "$XDG_CONFIG_HOME/task/taskrc"
mkdir -p "$XDG_CONFIG_HOME/waybar"
cp "$DOTFILES/waybar/"* "$XDG_CONFIG_HOME/waybar/"
mkdir -p "$XDG_CONFIG_HOME/wofi"
cp "$DOTFILES/wofi/"* "$XDG_CONFIG_HOME/wofi/"
mkdir -p "$HOME/.local/share/applications/"
cp "$DOTFILES/local/share/applications/browser.desktop" "$HOME/.local/share/applications/browser.desktop"
fi
return 0
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ motd ║
# ╚════════════════════════════════════════════════════════════════════════════╝
DOT_MOTD="$HOME/.motd"
[[ -e "$DOT_MOTD" ]] && source "$DOT_MOTD"
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Stoicism ║
# ╚════════════════════════════════════════════════════════════════════════════╝
fortune stoic
printf "\n"
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Stuff other programs dare to append goes here ║
# ╚════════════════════════════════════════════════════════════════════════════╝
#
# ...
# zprof