#!bash
# shellcheck disable=SC2239

if [[ $(type -t export-alias) == "" ]]; then
	function export-alias { builtin alias "$@"; }
fi

# enable color support of some commands and also add handy aliases
if [ "$TERM" != "dumb" ]; then
	eval "$(dircolors -b ~/.dircolors)"
	alias ls='ls --color=auto --group-directories-first'
	alias dir='ls --color=auto --format=vertical'
	alias vdir='ls --color=auto --format=long'
	alias grep='grep --color=auto'
	alias ncdu='ncdu --color=dark'
fi

# some more ls aliases
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'

# extend some commands with extra functionality
alias ssh=ssh-tweaks
alias task=task-local

alias urxvt-setfont-anonymous-pro='urxvt-setfont "Anonymous Pro"'
alias urxvt-setfont-cascadia-mono='urxvt-setfont "Cascadia Mono"'
alias urxvt-setfont-courier-prime='urxvt-setfont "Courier Prime Code"'
alias urxvt-setfont-fira-code='urxvt-setfont "Fira Code"'
alias urxvt-setfont-hack='urxvt-setfont "Hack"'
alias urxvt-setfont-inconsolata='urxvt-setfont "Inconsolata"'
alias urxvt-setfont-iosevka-fixed='urxvt-setfont "Iosevka Fixed SS11"'
alias urxvt-setfont-monospace='urxvt-setfont monospace 10'
alias urxvt-setfont-gohu-11='urxvt-setfont "GohuFont uni11 Nerd Font Mono" 11'
alias urxvt-setfont-gohu-14='urxvt-setfont "GohuFont uni14 Nerd Font Mono" 14'

export-alias alacritty-iosevka="alacritty -o 'font.normal.family=\"Iosevka Fixed\"' -o 'font.size=9'"
export-alias alacritty-iosevka-big="alacritty -o 'font.normal.family=\"Iosevka Fixed\"' -o 'font.size=14'"

export-alias nomi="ssh -C nomi.cz -t 'bash -l -c ~/bin/atmux'"
export-alias nomi-https="ssh -C nomi.cz-https -t 'bash -l -c ~/bin/atmux'"
export-alias nomi-mosh="MOSH_TITLE_NOPREFIX=1 mosh nomi.cz bin/atmux"

export-alias mutt-nomi='mutt -F ~/.config/mutt/muttrc-nomi'
export-alias neomutt-nomi='neomutt -F ~/.config/mutt/muttrc-nomi'

export-alias m='mutt-nomi'
export-alias m-tmux='tmuxp load m'

export-alias mutt-news-gmane='neomutt -g news.gmane.io'
export-alias mutt-news-kernel='neomutt -g nntp.lore.kernel.org'
#alias mutt-lkml='mutt -f news://nntp.lore.kernel.org/org.kernel.vger.linux-kernel'

# shellcheck disable=SC2016
export-alias wiki='"$EDITOR" ~/taskwiki/index.wiki'

# shellcheck disable=SC2016
export-alias git-dotfiles='git --git-dir="$HOME/src/dotfiles.git"'
alias git-dotfiles-export='export GIT_DIR="$HOME/src/dotfiles.git"'

export-alias livereload-make="python3 -c 'from livereload import Server, shell; server = Server(); server.watch(\".\", shell(\"make\")); server.serve();'"

export-alias google-chrome-app-diagrams="gtk-launch chrome-ilmgmogedobmcfegdjcibiiaodmdenpf-Default"
export-alias google-chrome-app-teams="gtk-launch chrome-cifhbcnohmdccbgoicgdjpfamggdegmo-Default"
export-alias google-chrome-app-discord="google-chrome --app=https://discord.com/app"
export-alias google-chrome-app-excalidraw="gtk-launch chrome-kmcnjdcipmgchfndpapkoecbidofdpbc-Default"
export-alias google-chrome-app-fb-messenger="google-chrome --app=https://www.messenger.com/"
export-alias google-chrome-app-goblin-tools-compiler="google-chrome --app=https://goblin.tools/Compiler"
export-alias google-chrome-app-goblin-tools-estimator="google-chrome --app=https://goblin.tools/Estimator"
export-alias google-chrome-app-goblin-tools-formalizer="google-chrome --app=https://goblin.tools/Formalizer"
export-alias google-chrome-app-goblin-tools-judge="google-chrome --app=https://goblin.tools/Judge"
export-alias google-chrome-app-google-chat="google-chrome --app=https://chat.google.com/"
export-alias google-chrome-app-keep="google-chrome --app=https://keep.google.com/"
export-alias google-chrome-app-matrix-element="google-chrome --app=https://app.element.io/"
export-alias google-chrome-app-skype="google-chrome --app=https://web.skype.com/"
export-alias google-chrome-app-wire="google-chrome --app=https://app.wire.com/"

export-alias google-chrome-profile-mitm="bwrap-pki-mitm google-chrome-profile"

export-alias cantata='LC_COLLATE=C /usr/bin/cantata'
export-alias virt-manager='LC_MESSAGES=C /usr/bin/virt-manager'

export-alias google-earth-pro='LC_NUMERIC=C /usr/bin/google-earth-pro'
export-alias google-earth='google-earth-pro'

export-alias nmcli-c-up-bluetooth='nmcli device connect 18:69:D4:0A:F6:0E'
export-alias nmcli-c-down-bluetooth='nmcli device disconnect 18:69:D4:0A:F6:0E'
export-alias bt-connect-qc45='bluetoothctl connect 78:2B:64:A0:68:02'
export-alias bt-disconnect-qc45='bluetoothctl disconnect 78:2B:64:A0:68:02'
export-alias bt-connect-buds='bluetoothctl connect B0:4A:6A:60:5E:A7'
export-alias bt-disconnect-buds='bluetoothctl disconnect B0:4A:6A:60:5E:A7'

export-alias mount-dropbox='systemctl --user start liskin-rclone-dropbox.service'
export-alias umount-dropbox='systemctl --user stop liskin-rclone-dropbox.service'

export-alias rofi-emoji-menu='EMOJI_FONT="emoji mono" ~/src/emoji-rofi-menu/emoji-menu.sh'
export-alias rofi-emoji-sign='EMOJI_FONT="emoji mono" ~/src/emoji-rofi-menu/emoji-sign.sh'
export-alias rofi-window='rofi -modi combi -combi-modi "window,browser:~/bin/rofi-plasma-browser-integration" -show combi'

export-alias steam='bwrap-steam /usr/games/steam'
export-alias protontricks='bwrap-steam /usr/bin/protontricks'

export-alias arbtt=liskin-arbtt-stats
export-alias arbtt-week='arbtt activity-chart ^sow tomorrow'

alias paste-x0at='curl -F "file=@-" https://x0.at/; echo'
alias paste-sprungeus='curl -F "sprunge=<-" http://sprunge.us; echo'

# /dev/rfkill is tagged uaccess in udev
export-alias rfkill=/usr/sbin/rfkill

# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=940511
export-alias yarn=yarnpkg

alias urldecode='python3 -c "import sys; from urllib.parse import unquote; sys.stdout.writelines(unquote(l.rstrip(\"\n\")) + \"\n\" for l in sys.stdin)"'
alias urlencode='python3 -c "import sys; from urllib.parse import quote; sys.stdout.writelines(quote(l.rstrip(\"\n\")) + \"\n\" for l in sys.stdin)"'

alias bel='echo -en "\007"'

alias vim='nvim'
alias view='nvim -R'
alias vimdiff='nvim -d'

alias luajit='rlwrap luajit'

alias taskw-timesheet='task timesheet "/^work /" or project:work'
alias taskw-log='task log project:work'
