#!/bin/zsh # Disable the gosh darn XON/XOFF function that serves no purpose but to confuse me when I accidentally press Ctrl+S stty -ixon if [[ $PATH != *$HOME/.local/bin:* ]]; then PATH=$HOME/.local/bin:$PATH fi # Set TZ if it's not set LOCALZONE=$(readlink -e /etc/localtime); export TZ=${TZ:-${LOCALZONE#/usr/share/zoneinfo/}} # Install EDITOR export EDITOR='nvim' # Install PAGER export PAGER='less --mouse' # Install BROWSER export BROWSER='firefox -P Mari --class Firefox.Main' # Set up the vim config path export VIM_CONFIG_DIR=$__COMMON_CONFIGS/vim # Run an SSH agent if one doesn't already exist and link the (new or existing) SSH auth socket to the central location if [[ ! -S $HOME/.ssh/ssh_auth_sock ]] && [[ ! -S $SSH_AUTH_SOCK ]] ; then eval $(ssh-agent -s | head -n1) fi if [[ -S $SSH_AUTH_SOCK ]] && [[ $SSH_AUTH_SOCK != $HOME/.ssh/ssh_auth_sock ]]; then ln -sf "$SSH_AUTH_SOCK" "$HOME/.ssh/ssh_auth_sock" fi SSH_AUTH_SOCK="$HOME/.ssh/ssh_auth_sock"; export SSH_AUTH_SOCK # Set potentially-destructive commands to use interactive modes alias rm='rm -I' alias cp='cp -i' alias mv='mv -i' function rmdirs() { RESULT=$(find $@ -not -type d) if [[ -z $RESULT ]]; then rm -Ir $@ else results=$(wc -l <<<$RESULT) >&2 echo "$results file(s) were found, please check again or run rm -Ir manually:" echo $RESULT | head -n10 >&2 if [[ $results -gt 10 ]]; then >&2 echo "... additional files elided" fi fi } function rmr() { find $@ -not -type d rm -Ir $@ } # Use a larger number of KDF rounds and the secure ed25519 key type by default. alias ssh-keygen="ssh-keygen -a 100 -b 4096 -t ed25519" # Reload this file's (and other customizations') aliases. function reload_zsh() { source "$HOME"/.zshrc } function dock() { xrandr --output DP-1 --auto --left-of eDP-1 pactl set-card-profile alsa_card.pci-0000_00_1f.3 output:hdmi-stereo-extra1+input:analog-stereo } function dock_off() { xrandr --output DP-1 --off pactl set-card-profile alsa_card.pci-0000_00_1f.3 output:analog-stereo+input:analog-stereo } # Check if the git repository is fully synced. # Pass --force-fetch to force the fetch to happen, even if one happened recently. function __common_configs_in_sync() { ( # Failure modes, in order: # exit 9: Problem cd'ing or getting commit hashes - things that should never fail cd $__COMMON_CONFIGS || exit 9 localCommit=$(git show-ref --verify --hash refs/heads/main) || exit 9 if [[ $1 == --force-fetch ]] || [[ ! -f .last-fetch ]] || [[ $(date --reference=.last-fetch +%s) -lt $(date --date='5 minutes ago' +%s) ]]; then git fetch --quiet origin && touch .last-fetch fi remoteCommit=$(git show-ref --verify --hash refs/remotes/origin/main) || exit 9 # exit 1: main is not the commit which is checked out. [[ $(git symbolic-ref HEAD) == "refs/heads/main" ]] || exit 1 # exit 2: main and origin/main are different. [[ $localCommit == $remoteCommit ]] || exit 2 # exit 3: There are staged changes. git diff-index --cached --exit-code --quiet HEAD || exit 3 # exit 4: There are unstaged changes. git diff-files --exit-code --quiet HEAD || exit 4 ) } # Enable built in help in the shell. export HELPDIR=/usr/share/zsh/help autoload run-help alias help=run-help