#!/bin/sh

# Some aliases
alias v="nvim"
alias abook="abook -C $HOME/.config/abook/abookrc --datafile $HOME/docs/data/contacts/addressbook"
alias ls="ls -hN --color=auto --group-directories-first"
alias units="units -H ''"
alias trans="trans -v -pager='less -R'"
alias lsdp="swaymsg -pt get_outputs | less"
alias op="xdg-open"
alias drag="dragon-drop"
wintitle() { printf "\033]2;%s\a" "$1";}
sass-watch() {
  while inotifywait -q -e create -e modify sass; do 
    sassc $1 $2
  done
}

# Generic shortcuts
alias music="ncmpcpp"
alias news="newsboat && killall -42 waybar"
alias audio="ncpamixer"
alias calc="python -q -i -c 'import math'"
alias spw="setsid $TERMINAL >/dev/null 2>&1 &"
alias testinet="ping -c2 example.com"
alias past="wl-paste -n"
alias ppast="wl-paste -pn"

# rsync shortcuts
alias rs="rsync -avhH"
alias rsn="rsync -avhHn"
alias rsd="rsync -avhH --delete"
alias rsdn="rsync -avhHn --delete"
alias rsg="rsync -avhH --delete --filter=':- .gitignore'"
alias rsgn="rsync -avhHn --delete --filter=':- .gitignore'"

# Fuzzy finder
if [ -f /usr/share/fzf/completion.zsh ]; then
	# Arch/Artix
	. /usr/share/fzf/completion.zsh
elif [ -f /usr/share/doc/fzf/examples/completion.zsh ]; then
	# Debian
	. /usr/share/doc/fzf/examples/completion.zsh
fi
if [ -f /usr/share/fzf/key-bindings.zsh ]; then
	# Arch/Artix
	. /usr/share/fzf/key-bindings.zsh
elif [ -f /usr/share/doc/fzf/examples/key-bindings.zsh ]; then
	# Debian
	. /usr/share/doc/fzf/examples/key-bindings.zsh
fi
bindkey -r '^T'
bindkey -r '\ec'
bindkey '^F' fzf-file-widget
bindkey '^A' fzf-cd-widget

# Function for changing working dir after exiting lf
lfcd () {
    tmp="$(mktemp)"
    lf -last-dir-path="$tmp" "$@"
    if [ -f "$tmp" ]; then
        dir="$(cat "$tmp")"
        rm -f "$tmp"
        if [ -d "$dir" ]; then
            if [ "$dir" != "$(pwd)" ]; then
                cd "$dir"
            fi
        fi
    fi
}

# Some keybindings
bindkey -s '^o' 'lfcd\n'
bindkey -s '^t' 'spw\n'

# Mounting drive shortcuts
alias mnt="udisksctl mount -b"
alias umnt="udisksctl unmount -b"
alias dlock="udisksctl lock -b"
alias dulock="udisksctl unlock -b"

# Internet
alias yt="youtube-dl --add-metadata -ic" # Download video link
alias yta="youtube-dl --add-metadata -xic" # Download only audio
alias YT="youtube-viewer"
alias starwars="telnet towel.blinkenlights.nl"

# git
gitcc () {
	git clone "$(wl-paste --no-newline)"
}

# Audio
alias mute="lmc mute"
alias vu="lmc up 5"
alias vd="lmc down 5"