2023-04-30 17:36:12 +02:00
|
|
|
#!/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)
|
2023-09-04 20:25:14 +02:00
|
|
|
to="$2"
|
2024-01-08 16:17:06 +01:00
|
|
|
[ ! -d "$(dirname $to)" ] && mkdir -p "$(dirname $to)"
|
2023-04-30 17:36:12 +02:00
|
|
|
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() {
|
2023-08-23 19:51:32 +02:00
|
|
|
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"
|
2023-04-30 17:36:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# List files in a directory and edit choosen one
|
|
|
|
vf(){
|
2023-08-23 19:51:32 +02:00
|
|
|
fd -L --maxdepth 1 --type f --color=never --hidden | fzf --prompt "Choose file to edit: " \
|
2023-04-30 17:36:12 +02:00
|
|
|
--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
|
|
|
|
}
|
2023-08-23 19:51:32 +02:00
|
|
|
|
|
|
|
# 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
|
2023-11-07 18:45:08 +01:00
|
|
|
NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
|
2023-08-23 19:51:32 +02:00
|
|
|
|
|
|
|
nnn "$@"
|
|
|
|
|
|
|
|
[ ! -f "$NNN_TMPFILE" ] || {
|
|
|
|
. "$NNN_TMPFILE"
|
|
|
|
rm -f "$NNN_TMPFILE" > /dev/null
|
|
|
|
}
|
|
|
|
}
|
2023-09-04 20:25:14 +02:00
|
|
|
|
|
|
|
upfast () {
|
|
|
|
curl -F "file=@$(readlink -f $1)" "https://upfast.cronyakatsuki.xyz/"
|
|
|
|
}
|
2023-10-24 18:10:42 +02:00
|
|
|
|
|
|
|
# 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
|
2024-01-08 16:17:48 +01:00
|
|
|
minc "$maildir/INBOX" > /dev/null
|
2023-10-24 18:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
2024-01-08 16:17:48 +01:00
|
|
|
minc "$maildir/INBOX" > /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
# Set mail as read
|
|
|
|
mread() {
|
|
|
|
mflag -S $1
|
|
|
|
mseq -f : | mseq -S
|
2023-10-24 18:10:42 +02:00
|
|
|
}
|
2024-01-08 16:44:58 +01:00
|
|
|
|
|
|
|
# Set the profile for mail management
|
|
|
|
mprofile() {
|
|
|
|
profiles=$(find "$HOME"/.config/mblaze -type f -exec basename "{}" \;)
|
|
|
|
currentMaildir=$(grep "^Maildir:" "$HOME"/.mblaze/profile | cut -d: -f 2 | sed 's/ //g')
|
|
|
|
|
|
|
|
[ -z "$1" ] && basename "$(grep -w "$currentMaildir" -l -R "$HOME"/.config/mblaze)" && exit 0
|
|
|
|
[ "$1" = "-l" ] && printf '%s\n' "$profiles" && exit 0
|
|
|
|
|
|
|
|
profile="$1"
|
|
|
|
|
|
|
|
if printf '%s\n' "$profiles" | grep -qw "$profile"; then
|
|
|
|
cp "$HOME"/.config/mblaze/"$profile" "$HOME"/.mblaze/profile
|
|
|
|
else
|
|
|
|
printf '%s\n' "This profile doesn't exist"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Mount a luks partition
|
|
|
|
mount-luks() {
|
|
|
|
# get the drive path
|
|
|
|
drive="$1"
|
|
|
|
|
|
|
|
# open the encrypted drive
|
|
|
|
sudo cryptsetup luksOpen $drive luks
|
|
|
|
|
|
|
|
# check if the /mnt/encrypted directory exists if not create it
|
|
|
|
[ -d "/mnt/encrypted/" ] || sudo mkdir -p /mnt/encrypted
|
|
|
|
|
|
|
|
# mount the decrypted drive to /mnt/encrypted/ directory
|
|
|
|
sudo mount /dev/mapper/luks /mnt/encrypted
|
|
|
|
}
|
|
|
|
|
|
|
|
umount-luks() {
|
|
|
|
sudo umount /dev/mapper/luks
|
|
|
|
sudo cryptsetup luksClose luks
|
|
|
|
}
|