Last active
November 19, 2024 12:31
-
-
Save SaphireLattice/97874aa1e9b846a60c83bb5f29567d85 to your computer and use it in GitHub Desktop.
My zshrc!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[ -o login ]] && source ~/.zshenv || touch ~/.zshenv # /etc/profile can override zshenv PATH | |
### ESSENTIALS ### | |
export TZ=Etc/GMT-6 | |
export LANG="en_GB.UTF-8" | |
export LANGUAGE="en_GB.UTF-8" | |
# XDG home config cleanup {{{ | |
export XDG_DATA_HOME=$HOME/.local/share | |
export XDG_CONFIG_HOME=$HOME/.config | |
export XDG_CACHE_HOME=$HOME/.cache | |
export XDG_STATE_HOME=$HOME/.local/state | |
#### General stuff | |
## GPG - see https://github.com/b3nj5m1n/xdg-ninja/issues/143 | |
#export GNUPGHOME="$XDG_DATA_HOME"/gnupg | |
## pass the password manager | |
export PASSWORD_STORE_DIR="$XDG_DATA_HOME"/pass | |
# IPFS | |
export IPFS_PATH="$XDG_DATA_HOME"/ipfs | |
#### Dev and languages | |
## Rust | |
export CARGO_HOME="$XDG_DATA_HOME"/cargo | |
export RUSTUP_HOME="$XDG_DATA_HOME"/rustup | |
## Docker | |
export DOCKER_CONFIG="$XDG_CONFIG_HOME"/docker | |
## Ruby | |
export GEM_HOME="$XDG_DATA_HOME"/gem | |
export GEM_SPEC_CACHE="$XDG_CACHE_HOME"/gem | |
## Golang | |
export GOPATH="$XDG_DATA_HOME"/go | |
export GOMODCACHE="$XDG_CACHE_HOME"/go/mod | |
## Gradle | |
export GRADLE_USERHOME="$XDG_DATA_HOME"/gradle | |
## Dotnet - Nuget and Omnisharp | |
export NUGET_PACKAGES="$XDG_CACHE_HOME"/NuGetPackages | |
export OMNISHARPHOME="$XDG_CONFIG_HOME"/omnisharp | |
## PlatformIO | |
export PLATFORMIO_CORE_DIR="$XDG_DATA_HOME"/platformio | |
## LaTeX texlive | |
export TEXMFVAR="$XDG_CACHE_HOME"/texlive/texmf-var | |
#### History files | |
# ZSH | |
export HISTFILE="$XDG_STATE_HOME"/zsh/history | |
## less pager | |
export LESSHISTFILE="$XDG_STATE_HOME"/less/history | |
# SQLite | |
export SQLITE_HISTORY="$XDG_STATE_HOME"/sqlite_history | |
## PostgreSQL CLI | |
export PSQL_HISTORY="$XDG_STATE_HOME/psql_history" | |
## node REPL mode history | |
export NODE_REPL_HISTORY="$XDG_STATE_HOME"/node_repl_history | |
## SHAME ZONE | |
# wget | |
alias wget=wget --hsts-file="$XDG_CACHE_HOME/wget-hsts" | |
# mitmproxy | |
alias mitmproxy="mitmproxy --set confdir=$XDG_CONFIG_HOME/mitmproxy" | |
alias mitmweb="mitmweb --set confdir=$XDG_CONFIG_HOME/mitmproxy" | |
# }}} | |
PATH=$PATH:$CARGO_HOME/bin:~/.local/bin/ | |
### COMPLETION ### | |
zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate | |
zstyle ':completion:*' expand prefix suffix | |
zstyle ':completion:*' file-sort name | |
# allow one error for every three characters typed in approximate completer | |
zstyle ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )' | |
# don't complete backup files as executables | |
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '(aptitude-*|*\~)' | |
# start menu completion only if it could find no unambiguous initial string | |
zstyle ':completion:*:correct:*' insert-unambiguous true | |
zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}' | |
zstyle ':completion:*:correct:*' original true | |
# activate color-completion | |
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} | |
# format on completion | |
zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}' | |
# automatically complete 'cd -<tab>' and 'cd -<ctrl-d>' with menu | |
# zstyle ':completion:*:*:cd:*:directory-stack' menu yes select | |
# insert all expansions for expand completer | |
zstyle ':completion:*:expand:*' tag-order all-expansions | |
zstyle ':completion:*:history-words' list false | |
# activate menu | |
zstyle ':completion:*:history-words' menu yes | |
# ignore duplicate entries | |
zstyle ':completion:*:history-words' remove-all-dups yes | |
zstyle ':completion:*:history-words' stop yes | |
zstyle ':completion:*:matches' group 'yes' | |
zstyle ':completion:*' group-name '' | |
zstyle ':completion:*' ignore-parents parent pwd .. directory | |
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s | |
zstyle ':completion:*' list-suffixes true | |
zstyle ':completion:*' matcher-list '' 'm:{[:upper:][:lower:]}={[:lower:][:upper:]}' '+r:|[._-]=**' '+r:|=**' '+l:|=* r:|=*' | |
#zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' '+r:|=*' '+l:|=*' | |
zstyle ':completion:*' max-errors 2 | |
zstyle ':completion:*' menu select | |
zstyle ':completion:*' preserve-prefix '//[^/]##/' | |
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s | |
zstyle ':completion:*' squeeze-slashes true | |
zstyle ':completion:*' use-compctl true | |
zstyle ':completion:*:messages' format '%d' | |
zstyle ':completion:*:options' auto-description '%d' | |
# describe options in full | |
zstyle ':completion:*:options' description 'yes' | |
# on processes completion complete all user processes | |
zstyle ':completion:*:processes' command 'ps -au$USER' | |
# offer indexes before parameters in subscripts | |
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters | |
# provide verbose completion information | |
zstyle ':completion:*' verbose true | |
zstyle ':completion:*:-command-:*:' verbose false | |
# complete manual by their section | |
zstyle ':completion:*:manuals' separate-sections true | |
zstyle ':completion:*:manuals.*' insert-sections true | |
zstyle ':completion:*:man:*' menu yes select | |
# Ignore completion functions for commands you don't have: | |
zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*' | |
# Provide more processes in completion of programs like killall: | |
zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq' | |
# command for process lists, the local web server details and host completion | |
zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html' | |
zstyle :compinstall filename '$HOME/.zshrc' | |
### HISTORY ### | |
HISTSIZE=100000 | |
SAVEHIST=100000 | |
DIRSTACKSIZE=8 | |
## Directories | |
setopt auto_pushd pushd_silent pushd_to_home | |
setopt cdable_vars | |
## Hash comments in interactive prompt | |
setopt interactive_comments | |
## History | |
setopt append_history | |
setopt extended_history | |
setopt hist_expire_dups_first | |
setopt hist_ignore_dups # ignore duplication command history list | |
setopt hist_ignore_space | |
setopt hist_verify | |
setopt inc_append_history | |
setopt share_history # share command history data | |
setopt complete_in_word | |
setopt no_hup | |
setopt no_beep | |
setopt pushd_ignore_dups | |
setopt no_globdots | |
setopt no_shwordsplit | |
### KEYBINDS ### | |
ZKBD_HOME=$XDG_CACHE_HOME/zkbd | |
autoload zkbd | |
function zkbd_file() { | |
[[ -f $ZKBD_HOME/${TERM}-${VENDOR}-${OSTYPE} ]] && printf '%s' "$ZKBD_HOME/${TERM}-${VENDOR}-${OSTYPE}" && return 0 | |
[[ -f $ZKBD_HOME/${TERM}-${DISPLAY} ]] && printf '%s' "$ZKBD_HOME/${TERM}-${DISPLAY}" && return 0 | |
return 1 | |
} | |
autoload -U select-word-style | |
select-word-style bash | |
[[ ! -d $ZKBD_HOME ]] && mkdir --parent $ZKBD_HOME | |
keyfile=$(zkbd_file) | |
ret=$? | |
#if [[ ${ret} -ne 0 ]]; then | |
# zkbd | |
# keyfile=$(zkbd_file) | |
# ret=$? | |
#fi | |
if [[ ${ret} -eq 0 ]] ; then | |
source "${keyfile}" | |
else | |
printf '\nFailed to setup keys using zkbd. Using sane default.\n' | |
typeset -g -A key | |
[[ -n "$terminfo[kf1]" ]] && key[F1]=$terminfo[kf1] | |
[[ -n "$terminfo[kf2]" ]] && key[F2]=$terminfo[kf2] | |
[[ -n "$terminfo[kf3]" ]] && key[F3]=$terminfo[kf3] | |
[[ -n "$terminfo[kf4]" ]] && key[F4]=$terminfo[kf4] | |
[[ -n "$terminfo[kf5]" ]] && key[F5]=$terminfo[kf5] | |
[[ -n "$terminfo[kf6]" ]] && key[F6]=$terminfo[kf6] | |
[[ -n "$terminfo[kf7]" ]] && key[F7]=$terminfo[kf7] | |
[[ -n "$terminfo[kf8]" ]] && key[F8]=$terminfo[kf8] | |
[[ -n "$terminfo[kf9]" ]] && key[F9]=$terminfo[kf9] | |
[[ -n "$terminfo[kf10]" ]] && key[F10]=$terminfo[kf10] | |
[[ -n "$terminfo[kf11]" ]] && key[F11]=$terminfo[kf11] | |
[[ -n "$terminfo[kf12]" ]] && key[F12]=$terminfo[kf12] | |
[[ -n "$terminfo[kf13]" ]] && key[F13]=$terminfo[kf13] | |
[[ -n "$terminfo[kf14]" ]] && key[F14]=$terminfo[kf14] | |
[[ -n "$terminfo[kf15]" ]] && key[F15]=$terminfo[kf15] | |
[[ -n "$terminfo[kf16]" ]] && key[F16]=$terminfo[kf16] | |
[[ -n "$terminfo[kf17]" ]] && key[F17]=$terminfo[kf17] | |
[[ -n "$terminfo[kf18]" ]] && key[F18]=$terminfo[kf18] | |
[[ -n "$terminfo[kf19]" ]] && key[F19]=$terminfo[kf19] | |
[[ -n "$terminfo[kf20]" ]] && key[F20]=$terminfo[kf20] | |
[[ -n "$terminfo[kbs]" ]] && key[Backspace]=$terminfo[kbs] | |
[[ -n "$terminfo[kich1]" ]] && key[Insert]=$terminfo[kich1] | |
[[ -n "$terminfo[kdch1]" ]] && key[Delete]=$terminfo[kdch1] | |
[[ -n "$terminfo[khome]" ]] && key[Home]=$terminfo[khome] | |
[[ -n "$terminfo[kend]" ]] && key[End]=$terminfo[kend] | |
[[ -n "$terminfo[kpp]" ]] && key[PageUp]=$terminfo[kpp] | |
[[ -n "$terminfo[knp]" ]] && key[PageDown]=$terminfo[knp] | |
[[ -n "$terminfo[kcuu1]" ]] && key[Up]=$terminfo[kcuu1] | |
[[ -n "$terminfo[kcub1]" ]] && key[Left]=$terminfo[kcub1] | |
[[ -n "$terminfo[kcud1]" ]] && key[Down]=$terminfo[kcud1] | |
[[ -n "$terminfo[kcuf1]" ]] && key[Right]=$terminfo[kcuf1] | |
#key[F1]='^[OP' | |
#key[F2]='^[OQ' | |
#key[F3]='^[OR' | |
#key[F4]='^[OS' | |
#key[F5]='^[[15~' | |
#key[F6]='^[[17~' | |
#key[F7]='^[[18~' | |
#key[F8]='^[[19~' | |
#key[F9]='^[[20~' | |
#key[F10]='^[[21~' | |
#key[F11]='^[[23~' | |
#key[F12]='^[[24~' | |
#key[Backspace]='^?' | |
#key[Insert]='^[[2~' | |
#key[Home]='^[[1~' | |
#key[PageUp]='^[[5~' | |
#key[Delete]='^[[3~' | |
#key[End]='^[[4~' | |
#key[PageDown]='^[[6~' | |
#key[Up]='^[[A' | |
#key[Left]='^[[D' | |
#key[Down]='^[[B' | |
#key[Right]='^[[C' | |
#key[Menu]='''' | |
fi | |
unfunction zkbd_file; unset keyfile ret | |
# setup key accordingly | |
[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line | |
[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line | |
[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode | |
[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char | |
[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history | |
[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history | |
[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char | |
[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char | |
[[ -n "${key[Delete]}" ]] && bindkey "^H" delete-word #^H | |
[[ -n "${key[Left]}" ]] && bindkey "^[[1;5D" backward-word #^[[1;5D | |
[[ -n "${key[Right]}" ]] && bindkey "^[[1;5C" forward-word #^[[1;5C | |
bindkey "^Q" push-input | |
### GPG-AGENT ### | |
#[[ ! -f ~/.gnupginf ]] && touch ~/.gnupginf | |
#export gnupginf="$HOME/.gnupginf" | |
#function gpg-agent-start() { | |
# source "$_gpg_agent_env" 2> /dev/null | |
# if [[ -z "$GPG_AGENT_INFO" && ! -S "${GNUPGHOME:-$HOME/.gnupg}/S.gpg-agent" ]]; then | |
# if ! pgrep -U "$USER" gpg-agent >/dev/null; then | |
# eval "$(gpg-agent --enable-ssh-support -s --daemon --log ~/.gnupg/gpg-agent.log | tee "$gnupginf")" 2> /dev/null | |
# fi | |
# export GPG_TTY="$(tty)" | |
# fi | |
#} | |
#function gpg-agent-reboot() { killall -9 -u "$USER" gpg-agent; gpg-agent-start } | |
#gpg-agent-start | |
function have() { | |
command -v $1 > /dev/null && return 0 || return 1 | |
} | |
### ZPLUG ### | |
ZPLUG_HOME=$XDG_DATA_HOME/zplug | |
[[ ! -d $ZPLUG_HOME ]] && | |
mkdir -p $ZPLUG_HOME && | |
git clone https://github.com/zplug/zplug.git $ZPLUG_HOME | |
if [[ -e $ZPLUG_HOME/init.zsh ]]; then | |
source $ZPLUG_HOME/init.zsh | |
autoload -Uz _zplugin | |
(( ${+_comps} )) && _comps[zplugin]=_zplugin | |
if [[ $ZPLUGIN_FIRST_TIME == 1 ]]; then | |
zplugin self-update | |
fi | |
zplug "zsh-users/zsh-completions" | |
zplug "zsh-users/zsh-syntax-highlighting" | |
zplug "zsh-users/zsh-history-substring-search" | |
#zplug "denysdovhan/spaceship-prompt" | |
zplug 'zplug/zplug', hook-build:'zplug --self-manage' | |
zplug "~/.zsh/", from:local | |
have nix && zplug "spwhitt/nix-zsh-completions" | |
have timew && zplug "svenXY/timewarrior" | |
if ! zplug check; then | |
zplug install | |
fi | |
#zplug load | |
### Substring-search plugin | |
#bindkey "${key[Up]}" history-substring-search-up | |
#bindkey "${key[Down]}" history-substring-search-down | |
### ZSH Spaceship theme | |
SPACESHIP_TIME_SHOW=true | |
SPACESHIP_HOST_PREFIX="@ " | |
SPACESHIP_HOST_SHOW=always | |
# Hide async indicating ellipsis | |
#spaceship remove async | |
fi | |
### END ZPLUG ### | |
autoload -Uz add-zsh-hook vcs_info | |
zstyle ':vcs_info:git:*' formats ' on %F{magenta} %b%f' | |
zstyle ':vcs_info:git:*' unstagedstr '?' | |
zstyle ':vcs_info:git:*' stagedstr '+' | |
setopt PROMPT_SUBST | |
function __spaceshippy_newline() { echo; vcs_info; } | |
add-zsh-hook precmd __spaceshippy_newline | |
function __spaceship_git_status() { | |
[[ $(command git rev-parse --is-inside-work-tree 2>/dev/null) == true ]] || return 1 | |
local INDEX git_branch="$vcs_info_msg_0_" git_status="" | |
INDEX=$(command git status --porcelain -b 2> /dev/null) | |
# Check whether branch is ahead | |
local ahead=$(command git rev-list --count ${git_branch}@{upstream}..HEAD 2>/dev/null) | |
local behind=$(command git rev-list --count HEAD..${git_branch}@{upstream} 2>/dev/null) | |
# Check wheather branch has diverged | |
if (( $ahead )) && (( $behind )); then | |
git_status+="⇕" | |
elif (( $ahead )); then | |
git_status+="⇡" | |
elif (( $behind )); then | |
git_status+="⇣" | |
fi | |
# Check for unmerged files | |
if $(echo "$INDEX" | command grep '^U[UDA] ' &> /dev/null); then | |
git_status+="=" | |
elif $(echo "$INDEX" | command grep '^AA ' &> /dev/null); then | |
git_status+="=" | |
elif $(echo "$INDEX" | command grep '^DD ' &> /dev/null); then | |
git_status+="=" | |
elif $(echo "$INDEX" | command grep '^[DA]U ' &> /dev/null); then | |
git_status+="=" | |
fi | |
# Check for stashes | |
if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then | |
git_status+="$" | |
fi | |
# Check for deleted files | |
if $(echo "$INDEX" | command grep '^[MARCDU ]D ' &> /dev/null); then | |
git_status+="✘" | |
elif $(echo "$INDEX" | command grep '^D[ UM] ' &> /dev/null); then | |
git_status+="✘" | |
fi | |
# Check for renamed files | |
if $(echo "$INDEX" | command grep '^R[ MD] ' &> /dev/null); then | |
git_status+="»" | |
fi | |
# Check for modified files | |
if $(echo "$INDEX" | command grep '^[ MARC]M ' &> /dev/null); then | |
git_status+="!" | |
fi | |
# Check for staged files | |
if $(echo "$INDEX" | command grep '^A[ MDAU] ' &> /dev/null); then | |
git_status+="+" | |
elif $(echo "$INDEX" | command grep '^M[ MD] ' &> /dev/null); then | |
git_status+="+" | |
elif $(echo "$INDEX" | command grep '^UA' &> /dev/null); then | |
git_status+="+" | |
fi | |
# Check for untracked files | |
if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then | |
git_status+="?" | |
fi | |
[[ -n $git_status ]] || return 1 | |
echo " %F{red}[$git_status]%f" | |
return 0 | |
} | |
PROMPT="%{%B%F{yellow}%}%*%f" # Kick off with bold, then yellow HH:MM:SS | |
PROMPT+=" in %F{cyan}%3~%f" # Cyan path, up to 3 dirs | |
if [[ -v SSH_CONNECTION ]]; then | |
PROMPT+=" as %F{yellow}%n%f" # yellow username on remote | |
fi | |
PROMPT+=" @ " | |
if [[ -v SSH_CONNECTION ]]; then | |
PROMPT+="%F{green}%m%f" # Blue hostname on local, green over SSH | |
else | |
PROMPT+="%F{blue}%m%f" # Blue hostname on local, green over SSH | |
fi | |
PROMPT+="\${vcs_info_msg_0_}\$(__spaceship_git_status)" | |
PROMPT+="%b" | |
PROMPT+=$'\n' | |
PROMPT+="%{%B%F{%(?.green.red)}%}➜ %{%b%f%}" # Cute lil' indicator, green normal and red on fail | |
autoload -Uz compinit bashcompinit | |
compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION" | |
bashcompinit | |
### FUNCTIONS ### | |
function bgr() { | |
(nohup "$@" &>/dev/null &) | |
} | |
function ix() { | |
local opts | |
local OPTIND | |
[ -f "$HOME/.netrc" ] && opts='-n' | |
while getopts ":hd:i:n:" x; do | |
case $x in | |
h) echo "ix [-d ID] [-i ID] [-n N] [opts]"; return;; | |
d) $echo curl $opts -X DELETE ix.io/$OPTARG; return;; | |
i) opts="$opts -X PUT"; local id="$OPTARG";; | |
n) opts="$opts -F read:1=$OPTARG";; | |
esac | |
done | |
shift $(($OPTIND - 1)) | |
[ -t 0 ] && { | |
local filename="$1" | |
shift | |
[ "$filename" ] && { | |
curl $opts -F f:1=@"$filename" $* ix.io/$id | |
return | |
} | |
echo "^C to cancel, ^D to send." | |
} | |
curl $opts -F f:1='<-' $* ix.io/$id | |
} | |
local function integrity_web() { | |
local ret=$(curl -sSL $1) | |
echo -nE "$ret" | |
} | |
function integrity() { | |
local getter="cat" | |
if [ -z "$1" ]; then | |
echo "URL or file required" | |
return | |
fi | |
if [ ! -f "$1" ]; then | |
getter="integrity_web" | |
fi | |
local method="$2" | |
if [ -z "$method" ]; then | |
method="sha384" | |
else | |
case $method in | |
sha256|sha384|sha512) ;; | |
md5) echo "Weak hash method!"; return;; | |
*) echo "Unsupported hash method!"; return;; | |
esac | |
fi | |
local hash=$($getter $1 | openssl dgst "-$method" -binary | openssl base64 -A | xargs -0 printf "$method-%s") | |
echo $hash | |
echo -n $hash | xclip -i -selection clipboard | |
} | |
function memuse() { | |
ps -eo size,pid,user,command | awk '{ hr=$1/1024 ; printf("%13.6f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%.80s ",$x) } print "" }' | sort -g | |
} | |
function update-discord() { | |
local log="$HOME/programs/DiscordCanaryUpdateLog" | |
touch $log | |
echo "$(date --rfc-3339=seconds -u)" >> $log | |
echo "Killing existing processes" | |
killall DiscordCanary; | |
killall DiscordCanary; | |
echo "Cleaning directory" | |
cd ~/programs; | |
rm -rf DiscordCanary; | |
echo "Downloading and unpacking" | |
wget https://discordapp.com/api/download/canary\?platform\=linux\&format\=tar.gz -O -| tar -azxv; | |
if [ -f "DiscordCanary/resources/build_info.json" ]; then | |
echo " - build info:" >> $log | |
cat DiscordCanary/resources/build_info.json >> $log | |
echo "" >> $log | |
else | |
echo " - no /resources/build_info.json found" >> $log | |
fi | |
if [ -f "DiscordCanary/chrome-sandbox" ]; then | |
echo " - has sandbox binary" >> $log | |
echo "Got sandbox binary, replacing..." | |
rm DiscordCanary/chrome-sandbox; | |
echo "Using chromium's binary, but no symlink is fine as well?" | |
#sudo ln -s /usr/lib/chromium/chrome-sandbox ~/programs/DiscordCanary/chrome-sandbox; | |
else | |
echo " - no sandbox binary" >> $log | |
fi | |
chmod +x DiscordCanary/DiscordCanary; | |
#bgr DiscordCanary/DiscordCanary; | |
cd -1 | |
} | |
function aria_list() { | |
local selectedFiles="$(aria2c -S $1| grep '[0-9]|' | sed -r 's/^\s*([0-9]+)\|/\1:/g' | fzf -d : --with-nth 2 -m --preview="echo -n {1}" --layout=reverse --preview-window=bottom:1:wrap)" | |
echo 'Download these files?' | |
echo "$selectedFiles" | sed "s/:/: /" | |
if read -q "REPLY?Download these files [y/N] "; then | |
echo; | |
local ids="$(echo "$selectedFiles" | cut -d: -f1 | tr '\n' ','| sed "s/,$//")" | |
aria2c $1 --select-file "$ids" | |
fi | |
echo; | |
} | |
function addr() { | |
local IFS="\n" | |
local ips=$(getent hosts $1 | awk '{ print $1 }') | |
echo $ips; | |
for ip in ips; do | |
sudo ip route add $ip via 192.168.90.1 dev wlp2s0b1; | |
done | |
} | |
function delr() { | |
local IFS="\n" | |
local ips=$(getent hosts $1 | awk '{ print $1 }') | |
for ip in ips; do | |
sudo ip route delete $ip | |
done | |
} | |
function updkey() { | |
gpg --fetch-key https://saphi.re/.well-known/saphire_gpg.key | |
#gpg --armor --export E367DE5F556078E229D5B5F258E83E36BFDCEE93 | ssh royalden "cat - > /srv/www/saphi.re/public/.well-known/saphire_gpg.key" && echo "Ok!" | |
gpg --armor --export 30DC4B69A96E648D9FE82659EA0452642C4DEC38 | ssh saphi.re "cat - > /srv/www/saphi.re/public/.well-known/saphire_gpg.key" && echo "Ok!" | |
} | |
function myip() { | |
curl icanhazip.com | |
} | |
function rsasign() { | |
local method="$2" | |
if [ -z "$method" ]; then | |
method="sha256" | |
else | |
case $method in | |
sha256|sha384|sha512) ;; | |
md5|sha1) echo "Weak hash method!"; return;; | |
*) echo "Unsupported hash method!"; return;; | |
esac | |
fi | |
local hash=$(cat - | openssl dgst "-$method" -sign $1 -binary | base64 -w 0) | |
echo $hash | |
} | |
function fedifetch() { | |
local key="$2" | |
if [ -z "$key" ]; then | |
key="$HOME/sources/site/public/private-key.pem" | |
fi | |
local curlMethod="$3" | |
if [ -z "$curlMethod" ]; then | |
curlMethod="GET" | |
fi | |
# extract the protocol | |
local proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')" | |
# remove the protocol | |
local url="$(echo ${1/$proto/})" | |
# extract the user (if any) | |
local user="" #$(echo $url | grep @ | cut -d@ -f1)" | |
# extract the host and port | |
local hostport="$(echo ${url/$user@/} | cut -d/ -f1)" | |
# by request host without port | |
local host="$(echo $hostport | sed -e 's,:.*,,g')" | |
# by request - try to extract the port | |
local port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')" | |
# extract the path (if any) | |
local urlpath="$(echo $url | grep / | cut -d/ -f2-)" | |
local rfcDate="$(LC_ALL=c date -u +"%a, %d %B %Y %H:%M:%S GMT")" | |
local signData="(request-target): ${curlMethod:l} /$urlpath\nhost: $hostport\ndate: $rfcDate" | |
local theSignature=$(echo -n "$signData" | rsasign $key) | |
echo "$signData" | |
echo -n "$signData" | hexdump -C | |
echo "$theSignature" | |
echo -n "$theSignature" | hexdump -C | |
curl -L -v\ | |
-X $curlMethod\ | |
-H "Date: $rfcDate"\ | |
-H 'User-Agent:'\ | |
-H 'Accept: application/activity+json'\ | |
-H "Signature: keyId=\"https://saphi.re/#main-key\",headers=\"(request-target) host date\",algorithm=\"hs2019\",signature=\"$theSignature\""\ | |
"$hostport/$urlpath" | |
} | |
### | |
#have starship && eval "$(starship init zsh)" | |
### ALIASES ### | |
alias sctl="sudo systemctl" | |
alias uctl="systemctl --user" | |
alias jlast="sudo journalctl -r" | |
alias ls="ls -v --color=auto" | |
have nvim && alias vim="nvim" | |
alias svim="sudo vim" | |
alias clip="xclip -i -selection clipboard" | |
alias dh="dirs -v" | |
alias swapd="cd -1" | |
alias mem="free -h" | |
alias uuid="uuidgen" | |
alias guid="guidgen" | |
alias ip="ip -color=auto" | |
alias xclipout="xclip -selection clipboard -out" | |
alias xclipin="xclip -selection clipboard -in" | |
have timew && alias tw=timew | |
have vim && EDITOR=vim || EDITOR=vi | |
have vim && VISUAL=vim || VISUAL=vi | |
if [ -f ~/.dircolors ]; then | |
eval $(dircolors ~/.dircolors) | |
fi | |
#SSH_AUTH_SOCK=/run/user/$UID/gnupg/S.gpg-agent.ssh; export SSH_AUTH_SOCK; | |
export SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/ssh-agent.socket | |
export SSH_ASKPASS=ksshaskpass | |
export SSH_ASKPASS_REQUIRE=prefer | |
export PATH=$PATH:~/.dotnet/tools | |
## Handled by /etc/profile.d/dotnet.sh | |
#export DOTNET_ROOT=/usr/share/dotnet | |
# Blur {{{ | |
if [[ $(ps --no-header -p $PPID -o comm) =~ '^yakuake|kitty$' ]]; then | |
for wid in $(xdotool search --pid $PPID); do | |
xprop -f _KDE_NET_WM_BLUR_BEHIND_REGION 32c -set _KDE_NET_WM_BLUR_BEHIND_REGION 0 -id $wid; | |
done | |
fi | |
# }}} | |
have task && task next || true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment