#  ______      #  ______       #  ________      #  ______    #
# /_____/\     # /_____/\      # /_______/\     # /_____/\   #
# \:::__\/     # \:::_ \ \     # \::: _  \ \    # \:::_ \ \  #
#  \:\ \  __   #  \:(_) ) )_   #  \::(_)  \ \   #  \:(_) \ \ #
#   \:\ \/_/\  #   \: __ `\ \  #   \:: __  \ \  #   \: ___\/ #
#    \:\_\ \ \ #    \ \ `\ \ \ #    \:.\ \  \ \ #    \ \ \   #
#     \_____\/ #     \_\/ \_\/ #     \__\/\__\/ #     \_\/   #
#                                                            #
# All unsorted junk below. Who knows what's in here.         #
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

# I hate these stupid dirs and every program that creates them.
nohup /bin/rmdir Desktop Documents Pictures Public \
        Templates Videos Music Nextcloud >/dev/null 2>&1 ||:

alias wasteland='v ~/src/dots/shell/wasteland.shellrc'

# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ranger() {
    if [ "$RANGER_LEVEL" ]; then
        exit
    else
        $(which ranger) "$@"
        clear
    fi
}
unalias r 2>/dev/null
alias r=ranger
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
alias {htop,htpo}='htop -d 10 -s PERCENT_CPU'
alias hme='htop -u mitch'
alias hroot='htop -u root'
alias hf='htop -F'
alias iotop='iotop -d 1 -o -P'

# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# youtube-dl / ffmpeg
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

# find res of a video file
alias res='ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0'

# removes audio from a video clip
removeaudio() {
    [ -f "$1" ] || return 1
    tmp=/tmp/$RANDOM.${1##.*}
    ffmpeg -i "$1" -c copy -an "$tmp" &&
    mv -f "$tmp" "${2:-out.mp4}"
}

# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# imagemagick
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
jpg() {
    if [ -f "$1" ] ; then
        jpegoptim -p -t -w $(($(nproc) / 2)) "$1"
    elif [ -d "${1:-.}" ] ; then
        printf 'This will recursively jpegoptim in current directory: %s\n' "$PWD"
        printf 'Confirm? (y/n):'
        read -r ans
        case $ans in
            *y*)
                find "${1:-.}" -type f -iname "*.jp*" -exec jpegoptim -p -t -w $(($(nproc) / 2)) {} \;
        esac
    fi
}

jpg-strip() {
    if [ -f "$1" ] ; then
        jpegoptim -s -p -t -w $(($(nproc) / 2)) "$1"
    elif [ -d "${1:-.}" ] ; then
        printf 'This will recursively jpegoptim in current directory: %s\n' "$PWD"
        printf 'Confirm? (y/n):'
        read -r ans
        case $ans in
            *y*)
                find "${1:-.}" -type f -iname "*.jp*" -exec jpegoptim -s -p -t -w $(($(nproc) / 2)) {} \;
        esac
    fi
}

# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# translate-shell
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
trans() { command trans -no-auto -b "$*" 2>/dev/null ; }
rtrans() { c=$1 ; shift ; command trans -from en -to $c "$*" 2>/dev/null ; }
rde() { rtrans de "$*" ; }
rja() { rtrans ja "$*" ; }
rru() { rtrans ru "$*" ; }

alias sshcfg='v ~/.ssh/config'
alias vimrc='v ~/.vimrc'
alias kittycfg='v ~/.config/kitty/kitty.conf'
alias i3cfg='v ~/.config/i3/config'

alias img2pdf='img2pdf *jpg --output combined.pdf'

alias detox='detox -v'

cuesplit() {
    case $1 in
        *h|*help)
            >&2 echo 'usage: cuesplit file.cue file.flac'
            break
            ;;
        *.cue)
            ;;
        *)
            break
    esac
    case $2 in
        *.flac|*.wav)
            ;;
        *)
            break
    esac
    shnsplit -f "$1" -o "flac flac -s -8 -o %f -" "$2" &&
    mv -v "$2" /tmp/ &&
    cuetag.sh "$1" *.flac
}

alias progress='progress -w -M'

pvcp() {
    if [ $# -ge 2 ] ; then
        case $2 in
            --delete)
                return 1
                ;;
            */)
                _file="${2%/}/${1##*/}"
                ;;
            *)
                if [ -d "$2" ] ; then
                    _file="${2%/}/${1##*/}"
                else
                    _file="$2"
                fi
        esac
        : > "$_file" || return 1
    else
        return 1
    fi
    if pv < "$1" > "$_file" ; then
        if [ "$3" = "--delete" ] ; then
            rm -f -- "$1"
        fi
    fi
}
pvmv() { pvcp "$1" "$2" --delete ; }

alias stop_typing_it_wrong_idiot="su -c faillock --user mitch --reset"

if command -v apt > /dev/null ; then
    alias  update='sudo apt update; sudo apt upgrade -y ; sudo apt dist-upgrade -y ; sudo apt clean'
fi


alias lxappearance='GDK_BACKEND=x11 lxappearance'

######## alias fixpulse='/usr/local/bin/pulseaudio --start --log-target=syslog'
alias nf=neofetch

alias {zramctl,zram}='zramctl --output-all'

alias ostui='ostui --config ~/.config/ostui --no-mpris --no-playlists'

# ========================================================================
# MPV aliases
# ========================================================================
alias mpvm='mpv --no-video'

# ========================================================================
# ambient noise
# ========================================================================
alias rain='sh ~/src/shit/shitty-bin/rain.sh'

# this is so annoying
readlink() { command readlink "${1%/}" ; }

# ========================================================================
# SWAY
# ========================================================================
# because i cant remember these
alias sway-outputs='swaymsg -t get_outputs'
alias sway-tree='swaymsg -t get_tree'
alias sway='exec ~/bin/misc/launch_sway.sh'
alias swaycfg='v ~/.config/sway/config'
alias waybarcfg='v ~/.config/waybar/config'

