dotfiles/.zshrc

172 lines
4.8 KiB
Bash

# .zshrc -- Samuel FORESTIER
## Enable Powerlevel10k instant prompt.
if [[ -r "${XDG_CACHE_HOME:-${HOME}/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-${HOME}/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
## Oh My ZSH auto-update
UPDATE_ZSH_DAYS=7
DISABLE_UPDATE_PROMPT="true"
## Some personal ZSH parameters
ENABLE_CORRECTION="true"
HYPHEN_INSENSITIVE="true"
COMPLETION_WAITING_DOTS="true"
HIST_STAMPS="dd.mm.yyyy"
## Antidote stuffs
### See <mattmc3/antidote#24>
autoload -Uz compinit && compinit
[[ -e ${ZDOTDIR:-~}/.antidote ]] ||
git clone https://github.com/mattmc3/antidote.git ${ZDOTDIR:-~}/.antidote
source ${ZDOTDIR:-~}/.antidote/antidote.zsh
zstyle ':antidote:bundle' use-friendly-names 'yes'
antidote load
autoload -Uz promptinit && promptinit && prompt powerlevel10k
## Personal old stuffs ported there
setopt dotglob # Makes `*` match hidden files too
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
## Let's setup beautiful CLI tools here !
if command -v bat > /dev/null 2>&1; then
alias cat='bat'
export MANPAGER="sh -c 'col -b | bat -l man -p'"
if command -v fzf > /dev/null 2>&1; then
source /usr/share/doc/fzf/examples/key-bindings.zsh
alias preview="fzf --preview 'bat --color \"always\" {}'"
export FZF_DEFAULT_OPTS="--height 90% --no-reverse"
export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'"
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:hidden:wrap --bind '?:toggle-preview'"
export FZF_CTRL_T_OPTS="--preview '((test -f {} && bat --color always {}) || tree -C {}) 2> /dev/null | head -200'"
fi
fi
if command -v prettyping > /dev/null 2>&1; then
alias ping='prettyping --nolegend'
fi
# Enforce Powerlevel10k configuration.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
alias ll="k"
alias ip="ip -color"
alias zsh_reload="src"
## Personal shell macros
# Personal SSH keys handler
keys()
{
if [[ "$1" == "up" ]]; then
# Let's load the keys into the SSH agent, for 1 hour
ssh-add -t 3600
elif [[ "$1" == "down" ]]; then
# Let's unload the keys (why would you do that ?)
ssh-add -D
else
# Just print out the loaded keys...
ssh-add -l
fi
}
# BigEndian to LittleEndian conversion (ZSH-compatible)
betole()
{
if [ -z "$1" ]; then
>&2 echo "Address needed !"
return 2
fi
echo -n "$1" | python3 -c 'import sys; a = sys.stdin.readlines()[0].replace("0x", ""); print("".join(["\\x" + a[i - 1] + a[i] for i in range(len(a) - 1, 0, -2)]))'
}
# String "sanitization" ("sluggifying" procedure)
strsan()
{
if [ -z "$1" ]; then
>&2 echo "String needed !"
return 2
fi
echo -n "$1" | python3 -c 'import re; import sys; print(re.sub(r"\W+", "-", sys.stdin.readlines()[0].strip().lower()).strip("-"))'
}
# Adds required padding to a given Base64 blob and decodes it !
pad64()
{
if [ -z "$1" ]; then
>&2 echo "Blob needed !"
return 2
fi
echo -n "$1" | python3 -c 'import sys; a = sys.stdin.readlines()[0].strip().rstrip("="); print(a + "=" * (4 - (len(a) % 4)))' | base64 -d
}
# Generate our user.js scripts
gen_firefox_userjs()
{
if [ -z "$1" ]; then
>&2 echo "Arkenfox User.JS version needed !"
return 2
fi
# Download specified Arkenfox User.JS scripts
wget -qN \
-P ~/.mozilla/firefox/*.default*/ \
"https://raw.githubusercontent.com/arkenfox/user.js/$(urlencode "$1")/"{user.js,prefsCleaner.sh,scratchpad-scripts/arkenfox-cleanup.js}
if [ $? -ne 0 ]; then
>&2 echo "Could not retrieve base scripts !"
return 1
fi
# Download and append our override script
wget -qO- \
"https://gist.githubusercontent.com/HorlogeSkynet/eda281b2b4ff6bb6674d77d4e823431a/raw/user-overrides.js" \
>> ~/.mozilla/firefox/*.default*/user.js
# Load Arkenfox cleanup JS script into clipboard
xclip -sel c < ~/.mozilla/firefox/*.default*/arkenfox-cleanup.js
# Ask user to go to about:config to run cleanup JS script
echo -n "Please go to <about:config> and press CTRL + SHIFT + K following by CTRL + V. Press enter when done !" \
&& read -r
# Kill running Firefox instances...
pkill -f firefox
# Run prefsCleaner
pushd ~/.mozilla/firefox/*.default*/ > /dev/null \
&& bash prefsCleaner.sh -s > /dev/null \
&& popd > /dev/null || return 1
}
gen_thunderbird_userjs()
{
if [ -z "$1" ]; then
>&2 echo "Thunderbird User.JS version needed !"
return 2
fi
# Download specified Thunderbird User.JS script
wget -qO- \
"https://raw.githubusercontent.com/HorlogeSkynet/thunderbird-user.js/$(urlencode "$1")/user.js" \
> ~/.thunderbird/*.default*/user.js
if [ $? -ne 0 ]; then
>&2 echo "Could not retrieve base script !"
return 1
fi
# Download and append our override script
wget -qO- \
"https://gist.githubusercontent.com/HorlogeSkynet/eda281b2b4ff6bb6674d77d4e823431a/raw/user-overrides_thunderbird.js" \
>> ~/.thunderbird/*.default*/user.js
}