mirror of
				https://github.com/ItsDrike/dotfiles.git
				synced 2025-11-04 01:16:35 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			245 lines
		
	
	
	
		
			8.8 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			245 lines
		
	
	
	
		
			8.8 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
#!/usr/bin/env zsh
 | 
						|
 | 
						|
# ----------------------------------------------------------------
 | 
						|
# Additional aliases
 | 
						|
alias cfextra='vim ~/.config/shell/extra'
 | 
						|
alias cflvim='lvim ~/.config/lvim/config.lua'
 | 
						|
alias cfgit='vim ~/.config/git/config'
 | 
						|
alias cfhypr="vim ~/.config/hypr/hyprland.conf"
 | 
						|
alias cfwaybar='vim ~/.config/waybar/config-hypr'
 | 
						|
alias dotsync='git checkout arch && git push && git checkout gentoo && git merge --ff arch && git push && git checkout arch'
 | 
						|
alias kbsk='setxkbmap sk qwerty'
 | 
						|
alias kbus='setxkbmap us'
 | 
						|
alias update-webpage='ssh webpage "cd /var/www/itsdrike.com; git pull; ./scripts/build.sh"'
 | 
						|
alias octave='octave --quiet'
 | 
						|
alias savekern='cp /proc/vmcore /root/crash.dump'
 | 
						|
alias discord-bump='sleep $((2*60*60)) && notify-send "Bump" "Bump time expired"'
 | 
						|
alias svim='nvim'
 | 
						|
alias vim='lvim'
 | 
						|
alias vpn-home='sudo systemctl stop wg-quick@wgivpn && sudo systemctl start wg-quick@wg0'
 | 
						|
alias vpn-ivpn='sudo systemctl stop wg-quick@wg0 && sudo systemctl start wg-quick@wgivpn'
 | 
						|
alias vpn-wg0='vpn-home'
 | 
						|
alias vpn-wgivpn='vpn-ivpn'
 | 
						|
alias vpn-off='sudo systemctl stop wg-quick@wg0 && sudo systemctl stop wg-quick@wgivpn'
 | 
						|
alias spotify-adblock='env LD_PRELOAD=/usr/lib/spotify-adblock.so spotify'
 | 
						|
alias mono-on='pacmd load-module module-remap-sink sink_name=mono master=2 channels=1'
 | 
						|
alias mono-off='pacmd unload-module module-remap-sink'
 | 
						|
 | 
						|
# ----------------------------------------------------------------
 | 
						|
# Additional functions
 | 
						|
 | 
						|
git-uni() {
 | 
						|
  git config --local commit.gpgsign false
 | 
						|
  git config --local user.email "p_vacho@utb.cz"
 | 
						|
  git config --local user.name "Peter Vacho"
 | 
						|
}
 | 
						|
 | 
						|
dot-sync() {
 | 
						|
    target="$(realpath -s "$1")"
 | 
						|
    if [[ "$target" == "$HOME/"* ]]; then
 | 
						|
        rel_path="$(realpath --relative-to="$HOME" "$target")"
 | 
						|
        dot_target="$dothome/$rel_path"
 | 
						|
    else
 | 
						|
        rel_path="$(realpath --relative-to="/" "$target")"
 | 
						|
        dot_target="$dotroot/$rel_path"
 | 
						|
    fi
 | 
						|
 | 
						|
    >&2 echo "Would copy $target -> $dot_target"
 | 
						|
    if [[ -d "$target" ]]; then
 | 
						|
        rsync -av --delete "${@:2}" "$target/" "$dot_target"
 | 
						|
    else
 | 
						|
        rsync -av "${@:2}" "$target" "$dot_target"
 | 
						|
    fi
 | 
						|
}
 | 
						|
 | 
						|
pytemp() {
 | 
						|
    dir="$(mktemp --tmpdir=/tmp -d "tmp.pytemp.XXXXXX")"
 | 
						|
    pushd "$dir" >/dev/null
 | 
						|
    yes "" | poetry init
 | 
						|
    cp ~/Personal/Programming/Python/Templates/GitHub/.flake8 .
 | 
						|
    sed -i 's/project_name/src/' ./.flake8
 | 
						|
    poetry add --dev flake8 black isort pyright  # also performs install
 | 
						|
    mkdir ./src
 | 
						|
    touch ./src/__init__.py
 | 
						|
    echo "def main():\n    ...\n\n" > ./src/__main__.py
 | 
						|
    echo "if __name__ == \"__main__\":\n    main()" >> ./src/__main__.py
 | 
						|
    poetry run lvim +2 -c 'execute "normal $ciw" | startinsert!' ./src/__main__.py
 | 
						|
    popd
 | 
						|
    rm -rf "$dir"
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
setuppy(){
 | 
						|
    cp -r "/home/itsdrike/Personal/Programming/Python/Templates/GitHub" "$1"
 | 
						|
    cd "$1"
 | 
						|
    git init
 | 
						|
    poetry update
 | 
						|
    poetry install
 | 
						|
    echo "TODO" >> .gitignore_local
 | 
						|
    poetry shell
 | 
						|
    # Show all places where we used "project_name", these are expected to be renamed
 | 
						|
    grep -RHIni --exclude-dir=.venv project_name
 | 
						|
}
 | 
						|
 | 
						|
webpage-put(){
 | 
						|
    scp $@ webpage:/var/www/itsdrike.com/etc
 | 
						|
}
 | 
						|
 | 
						|
webpage-remove(){
 | 
						|
    sftp webpage:/var/www/itsdrike.com/etc <<< "rm $@"
 | 
						|
}
 | 
						|
 | 
						|
vidtrim(){
 | 
						|
    if [ $# -ne 3 ]; then
 | 
						|
        echo "Invalid number of parameters passed!"
 | 
						|
        echo "Usage: vidtrim [file name] [start time] [end time]"
 | 
						|
        return 1
 | 
						|
    fi
 | 
						|
    no_ext_name=$1:r
 | 
						|
    ext=$1:e
 | 
						|
    i=1
 | 
						|
    while true; do
 | 
						|
        new_name="${no_ext_name}-trimmed-${i}.${ext}"
 | 
						|
        if [ -e "$new_name" ]; then
 | 
						|
            i=$((i + 1))
 | 
						|
        else
 | 
						|
            break
 | 
						|
        fi
 | 
						|
    done
 | 
						|
 | 
						|
    ffmpeg -ss "$2" -i "$1" -to "$3" -c copy -copyts "$new_name"
 | 
						|
}
 | 
						|
 | 
						|
vidmerge(){
 | 
						|
    if [ $# -lt 3 ]; then
 | 
						|
        echo "Invalid number of parameters passed!"
 | 
						|
        echo "Usage: vidmerge [input path 1] [input path 2] [optionally more inputs ...] [output name]"
 | 
						|
        echo "Example: vidmerge . REC-2020-05-.*.mp4 output.mp4"
 | 
						|
        return 1
 | 
						|
    fi
 | 
						|
 | 
						|
    # Parse the input
 | 
						|
    first_file="$1"
 | 
						|
    files="$2"
 | 
						|
    out="$3"
 | 
						|
    shift; shift; shift
 | 
						|
    # Process extra filenames, in case there's more than 2 to merge
 | 
						|
    while [ $# -gt 0 ]; do
 | 
						|
        files="$files\n$out"
 | 
						|
        out="$1"
 | 
						|
        shift
 | 
						|
    done
 | 
						|
 | 
						|
    # Prefer MP4Box over ffmpeg if installed
 | 
						|
    # this is benefitial because merging with ffmpeg results in files with
 | 
						|
    # messed up timeline (the file will be a merge product of all given files,
 | 
						|
    # but the timeline will suddenly skip i.e. from 10s to 50s seemlessly, resulting
 | 
						|
    # in proper merge, but with weird timeline info)
 | 
						|
    if ! command -v MP4Box >/dev/null 2>&1; then
 | 
						|
        files="$first_file\n$files"
 | 
						|
        # Create file with all of the file paths to concat for ffmpeg
 | 
						|
        substring="'"
 | 
						|
        if test "${files#*$substring}" != "$files"; then
 | 
						|
            echo "Can't handle files with $substring in their names!"
 | 
						|
            return 1
 | 
						|
        fi
 | 
						|
        loc="files.txt"
 | 
						|
        echo "$files" | while IFS= read -r line; do
 | 
						|
            printf "file '%s'\n" "$line" >> "$loc"
 | 
						|
        done
 | 
						|
 | 
						|
 | 
						|
        if ffmpeg -f concat -safe 0 -i "$loc" -c copy "$out"; then
 | 
						|
            rm "$loc"
 | 
						|
        else
 | 
						|
            echo "Ffmpeg failed, check '$loc' file, containing the files passed to ffmpeg"
 | 
						|
        fi
 | 
						|
    else
 | 
						|
        cat_list="$(echo "$files" | xargs -d '\n' printf -- '-cat "%s" ')"
 | 
						|
        cmd="MP4Box -add \"$first_file\" $cat_list \"$out\""
 | 
						|
        echo "$cmd"
 | 
						|
        if eval "$cmd"; then
 | 
						|
            echo "Video merge complete, generated output: $out"
 | 
						|
        else
 | 
						|
            echo "MP4Box failed, used cmd: $cmd"
 | 
						|
        fi
 | 
						|
    fi
 | 
						|
}
 | 
						|
 | 
						|
vidrot(){
 | 
						|
    if [ $# -ne 2 ]; then
 | 
						|
        echo "Invalid number of parameters passed!"
 | 
						|
        echo "Usage: vidrot [video file] [rotation (0/1/2/3)]"
 | 
						|
        echo "0: cclock_flip (90° counterclockwise and vertical flip)"
 | 
						|
        echo "1: clock (90° clockwise)"
 | 
						|
        echo "2: cclock (90° counterclockwise)"
 | 
						|
        echo "3: clock_flip (90° clockwise and vertical flip)"
 | 
						|
        return 1
 | 
						|
    fi
 | 
						|
    name="$1"
 | 
						|
    rotation="$2"
 | 
						|
    no_ext_name=$name:r
 | 
						|
    ext=$name:e
 | 
						|
    editname="${no_ext_name}-rot.${ext}"
 | 
						|
    ffmpeg -i "$name" -vf "transpose=$rotation" "$editname"
 | 
						|
}
 | 
						|
 | 
						|
# ----------------------------------------------------------------
 | 
						|
# Additional exports
 | 
						|
export dothome="$HOME/Personal/dotfiles/home"
 | 
						|
export dotroot="$HOME/Personal/dotfiles/root"
 | 
						|
export dotvim="$dothome/.config/nvim"
 | 
						|
 | 
						|
 | 
						|
# ----------------------------------------------------------------
 | 
						|
# Pacman/Emerge
 | 
						|
if command -v pacman > /dev/null; then
 | 
						|
    alias pkg-info='pacman -Si' # Info about a package in sync index
 | 
						|
    alias pkg-info-local='pacman -Qi' # Same as above, but for locally installed pkgs
 | 
						|
    alias pkg-file-owner='pacman -F' # Show package that owns given file in sync index
 | 
						|
    alias pkg-file-owner-regex='pacman -Fx' # Same as above, but works with partial names/regex
 | 
						|
    alias pkg-file-owner-local='pacman -Qo' # Same as above, but for locally installed pkgs
 | 
						|
    alias pkg-owned-files='pacman -Fl' # Show all files owned by given package in sync index
 | 
						|
    alias pkg-owned-files-local='pacman -Ql' # Same as above 2, but for locally installed pkgs
 | 
						|
    alias pkg-group-list='pacman -Sg' # List all pkgs that will be installed with a group
 | 
						|
    alias pkg-group-list-local='pacman -Qg' # Same as above, but from locally installed pkgs
 | 
						|
    alias pkg-orphans='pacman -Qtdq'
 | 
						|
 | 
						|
    alias pkg-get-upgrades='pacman -Syyuw' # Download new pkgs, but don't upgrade them
 | 
						|
    alias pkg-extract='pacman -Syw --cachedir .' # Download given pkg to current directory
 | 
						|
    alias pkg-clean-cache='pacman -Sc' # Remove old packages in pacman cache
 | 
						|
 | 
						|
    alias pkg-vuln-upgrade="pacman -Sy \"\$(arch-audit --upgradable --quiet | awk '{sub(/>=.+/, \"\"); print}' | paste -s -d ' ')\"" # Upgrade all vulnerable packages, with released fixes
 | 
						|
    alias vuln='arch-audit' # Show vulnerable packages that can be upgraded (Arch Linux)
 | 
						|
 | 
						|
    # Get fastest mirrors (using reflector)
 | 
						|
    alias mirror="sudo reflector -f 30 -l 30 --number 10 --verbose --save /etc/pacman.d/mirrorlist"
 | 
						|
    alias mirrord="sudo reflector --latest 50 --number 20 --sort delay --save /etc/pacman.d/mirrorlist"
 | 
						|
    alias mirrors="sudo reflector --latest 50 --number 20 --sort score --save /etc/pacman.d/mirrorlist"
 | 
						|
    alias mirrora="sudo reflector --latest 50 --number 20 --sort age --save /etc/pacman.d/mirrorlist"
 | 
						|
fi
 | 
						|
 | 
						|
if command -v emerge > /dev/null; then
 | 
						|
    if command -v eix > /dev/null; then
 | 
						|
        alias pkg-sync='eix-sync'
 | 
						|
        alias pkg-search='eix'
 | 
						|
    else
 | 
						|
        alias pkg-sync='emerge --sync --quiet=n'
 | 
						|
        alias pkg-search='emerge -s'
 | 
						|
    fi
 | 
						|
    alias pkg-update='emerge --update --deep @world'
 | 
						|
    alias pkg-upgrade='pkg-sync && pkg-update'
 | 
						|
    alias pkg-changed-use='pkg-update --changed-use'
 | 
						|
    alias pkg-recompile-all='emerge -e @world'
 | 
						|
 | 
						|
    alias pkg-which='equery which'
 | 
						|
    alias pkg-size='equery size'
 | 
						|
    alias pkg-depgraph='equery depgraph'
 | 
						|
    alias pkg-depends='equery depends'
 | 
						|
    alias pkg-check='equery check'
 | 
						|
    alias pkg-uses='equery uses'
 | 
						|
    alias pkg-keywords='equery keywords'
 | 
						|
 | 
						|
    alias update-conf='dispatch-conf'
 | 
						|
fi
 | 
						|
 |