gentoo-dots/.config/zsh/functions.zsh

121 lines
2.9 KiB
Bash
Executable File

#!/bin/sh
# Open a script in path with vim quicly
vish () {
nvim $(which $1)
}
# Create a directory and change into it
md () {
mkdir -p "$@" && cd "$@"
}
# Move a file and create a link in it's place
mvln () {
from=$(readlink -f $1)
to="$2"
[ ! -d "$(dirname $to)" ] && mkdir "$(dirname $to)"
mv $from $to
ln -s $to $from
}
# Find my script and let me edit them
se() {
fd . ~/bin -L --type f --color=never | fzf --prompt "Choose script to edit: " \
--preview 'bat --color=always --style=plain --pager=never {}' | xargs -r $EDITOR
}
# List my config and open the dir in a editor
ce() {
current=$(pwd)
dir=$(fd . ~/.config -L --maxdepth 1 --color=never | fzf --prompt \
"Choose config to edit: " --preview 'tree -a -C {}')
[ "$dir" = "" ] && return
cd "$dir" && nvim .
cd "$current"
}
# List files in a directory and edit choosen one
vf(){
fd -L --maxdepth 1 --type f --color=never --hidden | fzf --prompt "Choose file to edit: " \
--preview 'bat --color=always --style=plain --pager=never {}' | xargs -r $EDITOR
}
# Copy current working directory
cpdir() {
pwd | tr -d "\r\n" | xclip -sel c
}
# Copy content of a file.
cf() {
cat $1 | xclip -sel c
}
# Extract all archive in current path and remove the archive
erm() {
for file in *.zip; do
printf '%s\n' "Extracting $file"
unzip $file
rm -f $file
printf '%s\n' ""
done
}
# Check use flags of package in world
u() {
cat /var/lib/portage/world | fzf --prompt "Choose package to uninstall: " --preview "equery u {}" --multi
}
# Check dependencies of packages in world
d() {
cat /var/lib/portage/world | fzf --prompt "Choose package to uninstall: " --preview "emerge -pqe {}"
}
n () {
# Block nesting of nnn in subshells
[ "${NNNLVL:-0}" -eq 0 ] || {
echo "nnn is already running"
return
}
# Tempfile location
NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
nnn "$@"
[ ! -f "$NNN_TMPFILE" ] || {
. "$NNN_TMPFILE"
rm -f "$NNN_TMPFILE" > /dev/null
}
}
upfast () {
curl -F "file=@$(readlink -f $1)" "https://upfast.cronyakatsuki.xyz/"
}
# mblaze functions
# Get new mail for current profile
mnew () {
maildir=$(grep "^Maildir:" $HOME/.mblaze/profile | cut -d: -f 2 | sed 's/ //g')
profile=$(basename $maildir)
if [ "$profile" = "local" ]; then
mlist -s "$maildir"| msort -dr | mseq -S
else
mbsync -V $profile
mlist -s "$maildir"/INBOX | msort -dr | mseq -S
fi
}
# Get full mail for current profile including threads
mall () {
maildir=$(grep "^Maildir:" $HOME/.mblaze/profile | cut -d: -f 2 | sed 's/ //g')
sent=$(grep "^Outbox:" $HOME/.mblaze/profile | cut -d: -f 2 | sed 's/ //g')
profile=$(basename $maildir)
if [ "$profile" = "local" ]; then
mlist "$maildir" | mthread -r -S "$maildir" | mseq -S
else
mbsync -V $profile
mlist "$maildir"/INBOX | mthread -r -S "$sent" | mseq -S
fi
}