commit 94adc19b00e6d67b06ba83a5e5ae1116b6e68a2f Author: Jordan Atwood Date: Fri May 6 14:49:20 2022 -0700 Initial commit diff --git a/.user.gitconfig.dist b/.user.gitconfig.dist new file mode 100644 index 0000000..67b3e32 --- /dev/null +++ b/.user.gitconfig.dist @@ -0,0 +1,6 @@ +# example .user.gitconfig file for user/system-specific configs +[commit] + gpgsign = true +[user] + # get this via `gpg --list-secret-keys --keyid-format=short` + signingKey = 2D73A6DF diff --git a/README.md b/README.md new file mode 100644 index 0000000..75be018 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +dotfiles +======== + +## Features + +* A wealth of bash and git aliases scoured from the internet +* Beautiful terminal `PS1` and message-of-the-day-style prompt at start of session +* Sane defaults for shell options and builtins (`rm -I --preserve-root`, `mkdir -pv`, `grep --color=auto`, etc.) +* Config files and settings for [vim](https://www.vim.org/), [ripgrep](https://github.com/BurntSushi/ripgrep), + [abcde](http://lly.org/~rcw/abcde/page/), and [shellcheck](https://www.shellcheck.net/) + +## Setup + +1. Clone this repository into a directory of your choice. I recommend using the [`XDG_CONFIG_HOME` +directory](https://wiki.archlinux.org/title/XDG_Base_Directory#User_directories). (`$HOME/.config`) + + ```sh + cd "${XDG_CONFIG_HOME:-$HOME/.config}" + git clone https://git.example.com/nightfirecat/dotfiles.git + ``` + +2. Run `setup.sh` + + ```sh + "${XDG_CONFIG_HOME:-"$HOME"/.config}"/dotfiles/setup.sh + ``` + +Once completed, all necessary symlinks will be created for environment setup. Restart your login for the `.bash_profile` +to take effect. + +## Uninstall + +Run `setup.sh --remove` to clear any symlinks created by the setup process. diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..7d53778 --- /dev/null +++ b/setup.sh @@ -0,0 +1,46 @@ +#!/bin/bash +set -e + +# Accept the `--remove` argument to delete symlinks of the files to be copied +# This is useful for testing a clean installation (eg. `setup.sh --remove && setup.sh`) +# Note: Normal setup overwrites all old symlinks, so re-installation in place is idempotent +if [ "$1" == '--remove' ]; then + remove=1 +else + remove=0 +fi + +DIR="$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" +SRC_DIR="$DIR/src" + +# read file basenames to copy_files array +readarray -d '' copy_files < <(find "$SRC_DIR" -type f -printf '%f\0') +files_to_remove=() + +if [ $remove -eq 1 ]; then + for file in "${copy_files[@]}"; do + if [ -L "$file" ]; then + rm -v "$file" + else + echo "Skipping deletion of ${file} because it is not a symlink" + fi + done +elif [ $remove -eq 0 ]; then + # Ensure all files are absent in $HOME + for file in "${copy_files[@]}"; do + if [ -e "${HOME}/${file}" ] && ! [ -L "${HOME}/${file}" ]; then + files_to_remove+=( "$file" ) + fi + done + + if [ "${#files_to_remove}" -ne 0 ]; then + echo "Remove the following files from home directory and re-run setup!" + printf '%s\n' "${files_to_remove[@]}" + exit 1 + fi + + # Symlink files to $HOME, overwrite old symlinks + for file in "${copy_files[@]}"; do + ln -svf "${SRC_DIR}/${file}" "${HOME}/${file}" + done +fi diff --git a/src/.abcde.conf b/src/.abcde.conf new file mode 100644 index 0000000..8b5d4ae --- /dev/null +++ b/src/.abcde.conf @@ -0,0 +1,46 @@ +# Encode tracks immediately after reading. Saves disk space, gives better +# reading of 'scratchy' disks and better troubleshooting of encoding process +# but slows the operation of abcde quite a bit: +LOWDISK=y + +# Specify FLAC encoding +FLACENCODERSYNTAX=flac +FLAC=flac +OUTPUTTYPE="flac" + +# Set FLAC encoding options: (see `man flac`) +# -s: Silent operation +# -e: Exhaustive model search; gets best file size +# -V: Verify encoding process; ensures against encoding errors +# -8: Use highest compression for best file size +FLACOPTS='-s -e -V -8' + +# Label format for a standard 'single-artist', multi-track encode and also for +# a multi-track, 'various-artist' encode: +OUTPUTFORMAT='${OUTPUT}/${ARTISTFILE}/${ARTISTFILE} - ${ALBUMFILE}/${ARTISTFILE} - ${ALBUMFILE} - ${TRACKNUM} ${TRACKFILE}' +VAOUTPUTFORMAT='${OUTPUT}/Other, Various Artists/${ALBUMFILE}/${ALBUMFILE} ${TRACKNUM} - ${ARTISTFILE} - ${TRACKFILE}' + +# Label format for a standard 'single-artist', single-track encode and also for +# a single-track, 'various-artist' encode: +ONETRACKOUTPUTFORMAT='${OUTPUT}/${ARTISTFILE}/${ARTISTFILE} - ${TRACKFILE}' +VAONETRACKOUTPUTFORMAT='${OUTPUT}/Other, Various Artists/${ARTISTFILE} - ${TRACKFILE}' + +# Custom filenae munging: +# mungefilename receives the CDDB data (artist, track, title, whatever) as $1 +# and outputs it on stdout. +# This custom function will do the following: +# * Eat printable ASCII characters which are forbidden in Windows and Linux +# (<>:"/\|?*) and control characters +mungefilename () +{ + echo "$@" | tr -d "<>:\"/\\\\|?*[:cntrl:]" +} + +# Embed album art in addition to default actions +ACTIONS=default,embedalbumart + +# Use a padded two-digit track number (eg. 01 instead of 1) +PADTRACKS=y + +# Run two encoders simultaneously +MAXPROCS=2 diff --git a/src/.bash_logout b/src/.bash_logout new file mode 100755 index 0000000..d10d91b --- /dev/null +++ b/src/.bash_logout @@ -0,0 +1,6 @@ +#!/bin/bash + +# kill running ssh agent +if [ -n "$SSH_AUTH_SOCK" ]; then + eval "$(ssh-agent -k)" +fi diff --git a/src/.bash_profile b/src/.bash_profile new file mode 100755 index 0000000..56c403e --- /dev/null +++ b/src/.bash_profile @@ -0,0 +1,62 @@ +#!/bin/bash + +### environment vars +# Ensure $HOME/.bin exists, add it to PATH +mkdir -vp "$HOME/.bin" +export PATH="${PATH}:$HOME/.bin" + +# bash options +export HISTCONTROL=ignoreboth +export HISTSIZE=1000 +export HISTFILESIZE=5000 + +# XDG +export XDG_CACHE_HOME="$HOME/.cache" +export XDG_CONFIG_HOME="$HOME/.config" +export XDG_DATA_HOME="$HOME/.local/share" + +# Default editor +hash vim >/dev/null 2>&1 && export EDITOR='vim' VISUAL='vim' + +# Pager and man pager +if hash less >/dev/null 2>&1; then + # set sensible default for less + export LESS='-R' + + # Enhanced man pages + export MANPAGER='less -R -s -M' + + if [ "$(less -V | head -n 1 | cut -f 2 -d' ' )" -ge 580 ]; then + export MANPAGER="${MANPAGER} --use-color -Dd+r -Du+b" + else + # Add man page colors + # Sourced from: https://unix.stackexchange.com/a/329092/136537 + export LESS_TERMCAP_mb=$'\e[1;31m' # begin bold + export LESS_TERMCAP_md=$'\e[1;33m' # begin blink + export LESS_TERMCAP_so=$'\e[01;44;37m' # begin reverse video + export LESS_TERMCAP_us=$'\e[01;37m' # begin underline + export LESS_TERMCAP_me=$'\e[0m' # reset bold/blink + export LESS_TERMCAP_se=$'\e[0m' # reset reverse video + export LESS_TERMCAP_ue=$'\e[0m' # reset underline + export GROFF_NO_SGR=1 # for konsole and gnome-terminal + fi +fi + +# Maven +export JAVA_HOME=/lib/jvm/default-java +export PATH="${PATH}:/opt/maven/bin" + +# JShell +export CLASSPATH="/opt/libs/commons-lang3-3.7.jar:/opt/libs/guava-23.2-jre.jar" + +# rg config +export RIPGREP_CONFIG_PATH="$HOME"/.ripgreprc + +# shell check config +export SHELLCHECK_OPTS='--color' + +### commands +# Start SSH agent +if [ -z "$SSH_AUTH_SOCK" ]; then + eval "$(ssh-agent -s)" +fi diff --git a/src/.bashrc b/src/.bashrc new file mode 100755 index 0000000..5c86ea3 --- /dev/null +++ b/src/.bashrc @@ -0,0 +1,620 @@ +#!/bin/bash + +# If not running interactively, don't do anything +[ -z "$PS1" ] && return + +# source global definitions (if any) +if [ -f /etc/bashrc ]; then + # shellcheck disable=SC1091 + . /etc/bashrc +fi + + +### shell options +# set shell options +set -o ignoreeof # prevent Ctrl+D from exiting terminal +shopt -s cdspell # allow minor misspellings in `cd` commands +shopt -s checkhash # reference command hash table for executables +shopt -s checkwinsize # update LINES and COLUMNS after each command +shopt -s cmdhist # save all lines of multiline commands to history +shopt -s dotglob # allow globing filenames beginning with '.' +shopt -s expand_aliases # use bash aliases +shopt -s extglob # use pattern matching features (ref `man bash`) +shopt -s histappend # append to history file instead of overwriting +shopt -s histreedit # allow user to re-edit failed history appending +shopt -s histverify # edit recalled history line before executing +shopt -s hostcomplete # attempt hostname completion on word containing '@' +shopt -s lithist # save multiline commands to history with embedded \n +shopt -s nocaseglob # use case insensitive globs on filename expansion +shopt -s progcomp # use bash programmable completion +shopt -s promptvars # expand vars in prompt +shopt -s shift_verbose # print error if shifting out of bounds +shopt -s sourcepath # reference PATH to find executables + +# unset shell options +shopt -u mailwarn # don't spam mail read notifications +shopt -u nullglob # `ls nonexist/*` should fail, not act like `ls` + + +### define colors +# Normal colors +export COLOR_Black='\e[0;30m' +export COLOR_Red='\e[0;31m' +export COLOR_Green='\e[0;32m' +export COLOR_Yellow='\e[0;33m' +export COLOR_Blue='\e[0;34m' +export COLOR_Purple='\e[0;35m' +export COLOR_Cyan='\e[0;36m' +export COLOR_White='\e[0;37m' + +# Bright +export COLOR_BBlack='\e[1;30m' +export COLOR_BRed='\e[1;31m' +export COLOR_BGreen='\e[1;32m' +export COLOR_BYellow='\e[1;33m' +export COLOR_BBlue='\e[1;34m' +export COLOR_BPurple='\e[1;35m' +export COLOR_BCyan='\e[1;36m' +export COLOR_BWhite='\e[1;37m' + +# Background +export COLOR_On_Black='\e[40m' +export COLOR_On_Red='\e[41m' +export COLOR_On_Green='\e[42m' +export COLOR_On_Yellow='\e[43m' +export COLOR_On_Blue='\e[44m' +export COLOR_On_Purple='\e[45m' +export COLOR_On_Cyan='\e[46m' +export COLOR_On_White='\e[47m' + +# Color Reset +export COLOR_NC='\e[m' + +# Alert color (bright white on red) +export COLOR_ALERT="${COLOR_BWhite}${COLOR_On_Red}" + + +### aliases +# sensible defaults +alias sudo='sudo ' # allow sudo to execute aliases +alias rm='rm -I --preserve-root' +alias mv='mv -i' +alias cp='cp -i' +alias ln='ln -i' +alias chown='chown --preserve-root' +alias chmod='chmod --preserve-root' +alias chgrp='chgrp --preserve-root' +alias df='df -Th' +alias mkdir='mkdir -pv' +alias less='less -R' +alias grep='grep --color=auto' +alias egrep='egrep --color=auto' +alias fgrep='fgrep --color=auto' +alias diff='diff -uN --color=auto' +alias ip='ip --color=auto' +alias mount='mount | column -t' +alias tree='tree -Csuh' + +# simple shortcuts +alias aliases='alias -p' +alias h='history' +alias j='jobs -l' +alias which='type -a' +alias more='less' +alias path='echo -e ${PATH//:/\\n}' # print $PATH dirs on separate lines +alias now='date +"%T"' +alias nowtime='now' +alias nowdate='date +"%y-%m-%d"' +alias isodate='date -I' +alias isotime='date -Ihours' +alias headers='curl -I' # get site headers +alias headersc='curl -I --compress' # test gzip/mod_deflate support + +# add colors for filetype and human-readable sizes in `ls` +alias ls='ls -h --color --show-control-chars' +alias lx='ls -lXB' # sort by extension +alias lk='ls -lSr' # sort by date, newest first +alias lt='ls -ltr' # sort by date, newest last +alias lc='ls -ltcr' # sort by/show change time, most recent last +alias lu='ls -ltur' # sort by/show access time, most recent last + +# add `ll` and derivatives +alias ll='ls -lv --group-directories-first' +alias lm='ll | more' +alias lr='ll -R' +alias la='ll -A' + + +### functions +## private functions (internal use only) +# only performs `ssh-add` on files in ~/.ssh/ which have a header indicating +# they are SSH keys, and which are not loaded in the agent +function _bashrc_ssh-add-keys { + if ! grep -E -q -- '-BEGIN (OPENSSH|RSA) PRIVATE KEY-' ~/.ssh/*; then + return + fi + + local loaded_idents file + + loaded_idents="$(ssh-add -l)" + for file in ~/.ssh/*; do + if [ -f "$file" ] && \ + grep -E -q -- '-BEGIN (OPENSSH|RSA) PRIVATE KEY-' "$file" && \ + ! grep -q "$(ssh-keygen -lf "${file}.pub" | sed -E -e 's/^.+\b([^ ]+:[^ ]+)\b.+$/\1/' | tr -d '\n')" <<< "$loaded_idents"; + then + ssh-add "$file" + fi + done +} + +# test colors available in the terminal +# source: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html +function _bashrc_colortest { + local T FGs FG BG + T='gYw' # test text + + echo -e '\n 40m 41m 42m 43m' \ + ' 44m 45m 46m 47m'; + + for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' \ + ' 32m' '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' \ + ' 35m' '1;35m' ' 36m' '1;36m' ' 37m' '1;37m'; + do FG=${FGs// /} + echo -en " $FGs \\033[$FG $T " + for BG in 40m 41m 42m 43m 44m 45m 46m 47m; + do echo -en "$EINS \\033[$FG\\033[$BG $T \\033[0m"; + done + echo + done + echo +} + +# attempts to navigate to the passed path and print its canonical path +# (similar to `cd -`) +function _bashrc_.cd { + if cd "$1"; then + readlink -f . + fi +} + +# prints given elements in $2 ... joined by the string in $1 +function _bashrc_join_by { + if [ $# -lt 2 ]; then return 1; fi + + local d + + d="$1" + shift + echo -n "$1" + shift + printf '%s' "${@/#/$d}" +} + +# prints a human-readable time from a passed number of epoch seconds +function _bashrc_displaytime { + [ $# -ne 1 ] && echo "${FUNCNAME[0]}: 1 argument needed" >&2 && return 1 + + local T D H M S + T="$1" + D=$((T/60/60/24)) + H=$((T/60/60%24)) + M=$((T/60%60)) + S=$((T%60)) + [ "$D" -gt 0 ] && + echo -n "${D}d " + { [ "$D" -gt 0 ] || [ "$H" -gt 0 ]; } && + printf '%02.0fh ' "$H" + { [ "$D" -gt 0 ] || [ "$H" -gt 0 ] || [ "$M" -gt 0 ]; } && + printf '%02.0fm ' "$M" + printf '%02.0fs' "$S" +} + +# prints the code for a random color readable on a black background shell +# omits COLOR_White as it is indistinguishable from default color +function _bashrc_randomcolor { + local colors random_index + colors=( + # "$COLOR_Black" # cannot be read on black bg + "$COLOR_Red" + "$COLOR_Green" + "$COLOR_Yellow" + # "$COLOR_Blue" # very hard to read on black bg + "$COLOR_Purple" + "$COLOR_Cyan" + # "$COLOR_White" # indistinguishable from default color + "$COLOR_BRed" + "$COLOR_BGreen" + "$COLOR_BYellow" + "$COLOR_BBlue" + "$COLOR_BPurple" + "$COLOR_BCyan" + "$COLOR_BWhite" + ) + random_index="$(shuf -i 1-"${#colors[@]}" -n 1)" + random_index=$(( random_index - 1 )) + echo -e "${colors[$random_index]}" +} + +# prints a message of the day (time, shell info, system info, etc.) +function _bashrc_motd { + local kernel_string uptime_seconds uptime_msg cpuinfo cpu_model cpu_cores \ + cpu_msg k mem_decimals mem_units mem_label mem_percent_free \ + mem_danger_cutoff_limit mem_danger_cutoff_percent \ + mem_warning_cutoff_limit mem_warning_cutoff_percent mem_free_color \ + mem_msg + local -A memory + + # Print shell info + echo -e "$(_bashrc_randomcolor)This is BASH" \ + "$(_bashrc_randomcolor)${BASH_VERSION%.*}${COLOR_NC}" + kernel_string="$( + ( + uname -s + uname -r + uname -m + uname -o + ) | tr "\\n" ' ' + )" + echo -e "This kernel is: $(_bashrc_randomcolor)${kernel_string}${COLOR_NC}" + + # Print date and uptime + echo -e "It's $(_bashrc_randomcolor)$(date)${COLOR_NC}" + uptime_seconds="$(cut -d '.' -f 1 < /proc/uptime)" + uptime_msg="This machine has been up for $(_bashrc_randomcolor)" + uptime_msg+="$(_bashrc_displaytime "$uptime_seconds")${COLOR_NC}" + echo -e "$uptime_msg" + echo + + # Print CPU, memory, and HDD info + cpuinfo="$(cat /proc/cpuinfo)" + cpu_model="$( + grep -m 1 'model name' <<< "$cpuinfo" | + cut -d ':' -f 2 | + sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' + )" + cpu_cores="$( + grep -m 1 'cpu cores' <<< "$cpuinfo" | + cut -d ':' -f 2 | + sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' + )" + cpu_msg="CPU: $(_bashrc_randomcolor)${cpu_model} ${cpu_cores}-core processor" + cpu_msg+="${COLOR_NC}" + echo -e "$cpu_msg" + memory['free']='MemFree' + memory['total']='MemTotal' + for k in "${!memory[@]}"; do + memory["$k"]="$( + grep "${memory["$k"]}" < /proc/meminfo | + sed -r -e 's/^.+ ([[:digit:]]+).+$/\1/' + )" + (( memory["$k"] *= 1024 )) + done + # Determine memory divisor by available memory + mem_decimals=2 + if [ "${memory['free']}" -gt $(( 1024 * 1024 * 1024 )) ]; then + mem_units=$(( 1024 * 1024 * 1024 )) + mem_label='GiB' + elif [ "${memory['free']}" -gt $(( 1024 * 1024 )) ]; then + mem_units=$(( 1024 * 1024 )) + mem_label='MiB' + elif [ "${memory['free']}" -gt 1024 ]; then + mem_decimals=1 + mem_units=1024 + mem_label='KiB' + else + mem_decimals=0 + mem_units=1 + mem_label='B' + fi + # Determine memory "safety" by comparing available-to-total memory + # and by the following hard cutoffs for available memory: + # - available < 100mb or available / total < 0.1 :: danger + # - 100mb < available < 300mb or available / total < 0.3 :: warning + mem_percent_free="$( + awk -v free="${memory['free']}" -v total="${memory['total']}" \ + 'BEGIN { print free / total }' + )" + mem_danger_cutoff_limit="$(( 100 * 1024 * 1024 ))" + mem_danger_cutoff_percent='0.1' + mem_warning_cutoff_limit="$(( 300 * 1024 * 1024 ))" + mem_warning_cutoff_percent='0.3' + if ( + [ "${memory['free']}" -lt "$mem_danger_cutoff_limit" ] || + echo "$mem_percent_free" "$mem_danger_cutoff_percent" | \ + awk '{exit $1 < $2 ? 0 : 1}' + ); then + mem_free_color="${COLOR_BRed}" + elif ( + [ "${memory['free']}" -lt "$mem_warning_cutoff_limit" ] || + echo "$mem_percent_free" "$mem_warning_cutoff_percent" | \ + awk '{exit $1 < $2 ? 0 : 1}' + ); then + mem_free_color="${COLOR_BYellow}" + else + mem_free_color="${COLOR_BGreen}" + fi + # Format memory display + for k in "${!memory[@]}"; do + memory["$k"]="$( + awk -v m="${memory["$k"]}" -v u="$mem_units" -v d="$mem_decimals" \ + 'BEGIN { printf "%.*f", d, m / u }' + )" + done + mem_msg="Memory: ${mem_free_color}${memory['free']}${COLOR_NC}/" + mem_msg+="${COLOR_BWhite}${memory['total']}${COLOR_NC} ${mem_label} available" + echo -e "$mem_msg" + echo 'HDDs:' + echo -en "$(_bashrc_randomcolor)" && + df -mh \ + --type=btrfs \ + --type=ext4 \ + --type=ext3 \ + --type=ext2 \ + --type=vfat \ + --type=tiso9660 \ + --type=xfs \ + --type=fuseblk \ + --type=ntfs \ + && + echo -en "${COLOR_NC}" + echo +} + +# returns completion items for .* functions +# notably returns files/dirs in parent directories from PWD +function _bashrc_.complete { + local cmd word + cmd="$1" + word=${COMP_WORDS[COMP_CWORD]} + + if ! grep -q -E '^\.[.1-9]$' <<< "$cmd"; then + echo "${FUNCNAME[0]}: parent function must match '.[.1-9]'" + return 1 + fi + + local parent_depth path_array i parent_path word_list matched_word + parent_depth="${cmd//.}" + if [ -z "$parent_depth" ]; then + parent_depth=1 + fi + path_array=() + for (( i=0; i${FUNCNAME[0]}<" ;; + esac + else + echo "'$1' is not a valid file!" + fi +} + +# functions for fast traversal through parent directories +# each processes at most one parameter containing the path to traverse +# after going up N levels, where N is the number in the function name +function .. { + .1 "$1" +} + +function .1 { + local prepend_path + prepend_path=.. + _bashrc_.cd "${prepend_path}/${1}" +} + +function .2 { + local prepend_path + prepend_path=../.. + _bashrc_.cd "${prepend_path}/${1}" +} + +function .3 { + local prepend_path + prepend_path=../../.. + _bashrc_.cd "${prepend_path}/${1}" +} + +function .4 { + local prepend_path + prepend_path=../../../.. + _bashrc_.cd "${prepend_path}/${1}" +} + +function .5 { + local prepend_path + prepend_path=../../../../.. + _bashrc_.cd "${prepend_path}/${1}" +} + +function .6 { + local prepend_path + prepend_path=../../../../../.. + _bashrc_.cd "${prepend_path}/${1}" +} + +function .7 { + local prepend_path + prepend_path=../../../../../../.. + _bashrc_.cd "${prepend_path}/${1}" +} + +function .8 { + local prepend_path + prepend_path=../../../../../../../.. + _bashrc_.cd "${prepend_path}/${1}" +} + +function .9 { + local prepend_path + prepend_path=../../../../../../../../.. + _bashrc_.cd "${prepend_path}/${1}" +} + + +# programmable completion +# source available completion file +if [ -f /etc/bash_completion ]; then + # shellcheck disable=SC1091 + . /etc/bash_completion +fi + +# common completions +complete -A hostname rsh rcp telnet rlogin ftp ping disk +complete -A export printenv +complete -A variable export local readonly unset +complete -A enabled builtin +complete -A alias alias unalias +complete -A function function +complete -A user su mail finger +complete -A helptopic help +complete -A shopt shopt +complete -A stopped -P '%' bg +complete -A job -P '%' fg jobs disown +complete -A directory mkdir rmdir +complete -A directory -o default cd + +# compression +complete -f -o default -X '*.+(zip|ZIP)' zip +complete -f -o default -X '!*.+(zip|ZIP)' unzip +complete -f -o default -X '*.+(z|Z)' compress +complete -f -o default -X '!*.+(z|Z)' uncompress +complete -f -o default -X '*.+(gz|GZ)' gzip +complete -f -o default -X '!*.+(gz|GZ)' gunzip +complete -f -o default -X '*.+(bz2|BZ2)' bzip2 +complete -f -o default -X '!*.+(bz2|BZ2)' bunzip2 +complete -f -o default -X '!*.+(zip|ZIP|z|Z|gz|GZ|xz|XZ|bz2|BZ2)' extract + +complete -f -o default -X '!*.pl' perl perl5 + +complete -F _bashrc_.complete .. .1 .2 .3 .4 .5 .6 .7 .8 .9 + +### run setup +# load SSH keys +_bashrc_ssh-add-keys + +# echo motd +_bashrc_motd + +# sets PS1, appends to history +PROMPT_COMMAND="_bashrc_prompt_command" +PS2='\[$(_ps1_color preprompt)\]>\[$(_ps1_color prompt)\] ' diff --git a/src/.gitconfig b/src/.gitconfig new file mode 100644 index 0000000..b9ba1ee --- /dev/null +++ b/src/.gitconfig @@ -0,0 +1,63 @@ +[alias] + alias = !git config --get-regexp '^alias\\.' | cut -d '.' -f '2-' | sed -re 's/^([^ ]+) /\\1*/g' | column -s '*' -t | sort + amend = commit --amend --no-edit + amend-all = commit -a --amend --no-edit + # TODO: fix below; that method is not accurate +# check-merge = "!f() { output=$(git format-patch ${1:-master} --stdout | git apply --3way --check - 2>/dev/null); exit_code=$?; if [ $exit_code != '0' ] && [ $exit_code != '128' ]; then echo 'Merge conflicts exist! See `git apply` output below:'; echo; echo $output; fi; }; f" + co-pr = "!f() { [ $# -ne 2 ] && echo 'Two arguments required, PR # and branch name' && exit 1; git fetch upstream pull/$1/head:$2-$1 && git checkout $2-$1 && git merge master --no-gpg-sign --no-edit; }; f" + fixup = commit --amend --no-edit + ll = log --pretty=format:"%C(yellow)%h%C(red)%d%C(reset)\\ %s\\ %C(blue)%C(bold)[%aN]%C(reset)" --decorate --numstat + lo = log --oneline --decorate + ls = log --pretty=format:"%C(yellow)%h%C(red)%d%C(reset)\\ %s\\ %C(blue)%C(bold)[%aN]%C(reset)" --decorate + lsd = log --pretty=format:"%C(yellow)%h\\ %ad%C(red)%d%C(reset)\\ %s\\ %C(blue)%C(bold)[%aN]%C(reset)" --decorate --date=short + lsdr = log --pretty=format:"%C(yellow)%h\\ %ad%C(red)%d%C(reset)\\ %s\\ %C(blue)%C(bold)[%aN]%C(reset)" --decorate --date=relative + pullf = pull --ff-only + pullfsur = !git pull --ff-only && git submodule update --recursive + pullr = pull --rebase + pullrp = !git pull --rebase && git push + pullrsur = !git pull --rebase && git submodule update --recursive + pullrsurp = !git pull --rebase && git submodule update --recursive && git push + reword = commit --amend + sur = submodule update --recursive +[apply] + whitespace = fix +[branch] + autosetupmerge = always + autosetuprebase = always +[color] + branch = auto + diff = auto + interactive = true + status = auto +[core] + autocrlf = false + fscache = true + longpaths = true + pager = less -x1,5 + whitespace = cr-at-eol,tabwidth=4,trailing-space +[diff] + colormoved = default + renames = copies + submodule = log + wsErrorHighlight = old,new +[diff "astextplain"] + # diff document files based on their text contents rather than binaries + textconv = astextplain +[fetch] + prune = true +[help] + autocorrect = 20 +[include] + # Define system-specific user configs such as GPG signing key + path = ~/.user.gitconfig +[push] + default = current +[rebase] + autosquash = true +[status] + submodulesummary = true +[submodule] + fetchjobs = 0 +[user] + name = Jordan Atwood + email = nightfirecat@nightfirec.at diff --git a/src/.inputrc b/src/.inputrc new file mode 100644 index 0000000..62e4d0a --- /dev/null +++ b/src/.inputrc @@ -0,0 +1,41 @@ +# This file controls the behavior of line input editing for programs which use +# the GNU Readline library. +# +# The inputrc file can be re-read using . +# Lines beginning with '#' are comments. + +# Include any system-wide bindings and variable assignments from /etc/Inputrc +$include /etc/inputrc + +# Performs filename matching and completion in a case-insensitive fashion. +set completion-ignore-case on + +# Treat hyphens (-) and underscores (_) as equivalent when performing case-insensitive filename matching and completion. +# Requires `completion-ignore-case on` +set completion-map-case on + +# Configure the terminal in a way that will enable it to insert each paste into the editing buffer as a single string of +# characters, instead of treating each character as if it had been read from the keyboard. This can prevent pasted +# characters from being interpreted as editing commands. +set enable-bracketed-paste + +# Displays possible completions using different colors to indicate their file type. +set colored-stats on + +# Completed names which are symbolic links to directories have a slash appended. +set mark-symlinked-directories on + +# Words which have more than one possible completion cause the matches to be listed immediately instead of ringing the +# bell. +set show-all-if-ambiguous + +# Do not insert characters from the completion that match characters after point in the word being completed, so +# portions of the word following the cursor are not duplicated. +set skip-completed-text on + +# Add history searching. That is, map the up and down arrow keys to search for +# completions from the current line from command history. +# eg. If "git" is typed, hitting UP will move to the most recent "git" command +# in history. +"\e[A": history-search-backward +"\e[B": history-search-forward diff --git a/src/.ripgreprc b/src/.ripgreprc new file mode 100644 index 0000000..ee58dc1 --- /dev/null +++ b/src/.ripgreprc @@ -0,0 +1,13 @@ +# https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#configuration-file + +# Limit output width +--max-columns=150 + +# Print Unix-style paths +--path-separator=/ + +# Search hidden files and directories +--hidden + +# Don't search .git directories +--glob=!.git diff --git a/src/.vimrc b/src/.vimrc new file mode 100644 index 0000000..f2283c4 --- /dev/null +++ b/src/.vimrc @@ -0,0 +1,94 @@ +" When started as "evim", evim.vim will already have done these settings, bail +" out. +if v:progname =~? "evim" + finish +endif + +" Get the defaults that most users want +source $VIMRUNTIME/defaults.vim + +" Don't keep context lines around cursor +set scrolloff=0 + +" do not keep backup files or undo files (they clutter filesystem) +set nobackup +set noundofile + +" Put these in an autocmd group so that we can delete them easily +augroup vimrc + au! + + " For all text files set 'textwidth' to 80 characters + autocmd FileType text setlocal textwidth=80 +augroup END + +" Add optional packages +" +" The matchit plugin makes the % command work better, but it is not backwards +" compatible. +" The ! means the package won't be loaded right away but when plugins are +" loaded during initialization. +if has('syntax') && has('eval') + packadd! matchit +endif + +" Enable re-use of the same window to switch from an unsaved buffer without +" saving it first. Also allows you to keep an undo history for multiple files +" when re-using the same window in this way. +set hidden + +" Highlight searches (use to temporarily turn off highlighting; see the +" mapping of below) +if &t_Co > 2 || has("gui_running") + set hlsearch +endif + +" Use case insensitive search, except when using capital letters +set ignorecase +set smartcase + +" When opening a new line and no filetype-specific indenting is enabled, keep +" the same indent as the line you're currently on. Useful for READMEs, etc. +set autoindent + +" Stop certain movements from always going to the first character of a line. +" While this behavior deviates from that of Vi, it does what most users coming +" from other editors would expect. +set nostartofline + +" Instead of failing a command because of unsaved changes, instead raise a +" dialogue asking if you wish to save changed files. +set confirm + +" Use visual bell instead of beeping when doing something wrong +set visualbell + +" And reset the terminal code for the visual bell. If visualbell is set, and +" this line is also included, vim will neither flash nor beep. If visualbell +" is unsetl, this does nothing. +set t_vb= + +" Set the command window height to 2 lines, to avoid many cases of having to +" "press to continue" +set cmdheight=2 + +" Quickly time out on keycodes, but never time out on mappings +set notimeout ttimeout ttimeoutlen=200 + +" Use to toggle between 'paste' and 'nopaste' +set pastetoggle= + +" Use 4-width tabs +" Force tabs over spaces for indentation +" Use one tab when using Vim shifts +set tabstop=4 softtabstop=0 noexpandtab shiftwidth=4 + +" Jump to last position when reopening a file +if has('autocmd') + au BufReadPost * if line ("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif + autocmd BufReadPost COMMIT_EDITMSG | exe "normal! gg" +endif + +" Map (redraw screen) to also turn off search highlighting until the +" next search +nnoremap :nohl