2022-01-08 15:24:29 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# shellcheck source=./.zstyle
|
|
|
|
source ~/.zstyle
|
|
|
|
|
2022-02-26 20:26:33 -06:00
|
|
|
. "${HOME}/.cargo/env"
|
2022-01-08 15:24:29 -06:00
|
|
|
|
|
|
|
### Pathing ###
|
|
|
|
|
|
|
|
export PATH="${HOME}/.bin:${PATH}"
|
|
|
|
export PATH="${PATH}:/opt/homebrew/Cellar/llvm/13.0.0_2/bin"
|
|
|
|
|
|
|
|
# Mac pathing beneath
|
2022-01-14 01:40:44 -06:00
|
|
|
if [[ "${OSTYPE}" = "darwin"* ]]; then
|
2022-01-08 15:24:29 -06:00
|
|
|
export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:${PATH}"
|
|
|
|
export MANPATH="/opt/homebrew/opt/coreutils/libexec/gnuman:${MANPATH}"
|
2022-02-19 13:35:06 -06:00
|
|
|
|
|
|
|
# Python with pyenv
|
|
|
|
eval "$(pyenv init --path)"
|
|
|
|
eval "$(pyenv init -)"
|
2022-03-07 14:50:15 -06:00
|
|
|
|
|
|
|
# LLDB
|
|
|
|
export PATH="/opt/homebrew/opt/llvm/bin:${PATH}"
|
2022-01-08 15:24:29 -06:00
|
|
|
fi
|
|
|
|
|
2022-01-08 19:16:41 -06:00
|
|
|
### OPTS ###
|
|
|
|
setopt extendedglob
|
2022-01-14 12:02:52 -06:00
|
|
|
setopt nullglob
|
2022-01-08 19:16:41 -06:00
|
|
|
|
2022-01-08 15:24:29 -06:00
|
|
|
### Environment Variables ###
|
|
|
|
export LANG=en_US.UTF-8
|
2022-01-08 19:35:30 -06:00
|
|
|
if [[ -f "/usr/libexec/java_home" ]]; then
|
|
|
|
export JAVA_HOME="$(/usr/libexec/java_home)"
|
|
|
|
fi
|
2022-01-08 15:24:29 -06:00
|
|
|
export AWS_CLI_AUTO_PROMPT=on
|
|
|
|
export ZSH_HIGHLIGHT_MAXLENGTH=10000
|
|
|
|
export ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=2
|
|
|
|
export LANG=en_US.UTF-8
|
2022-01-14 12:02:52 -06:00
|
|
|
export NOTES_DIR="${HOME}/.notes"
|
2022-02-25 14:57:24 -06:00
|
|
|
export DOCKER_BUILDKIT=1
|
2022-01-08 15:24:29 -06:00
|
|
|
|
2022-01-14 01:40:44 -06:00
|
|
|
# Fzf Variables
|
|
|
|
export FZF_DEFAULT_OPTS="--height=80% --layout=reverse --info=inline --border --margin=1 --padding=1"
|
|
|
|
|
2022-01-08 15:24:29 -06:00
|
|
|
if which nvim >/dev/null 2>&1; then
|
|
|
|
export EDITOR=nvim
|
|
|
|
export VISUAL=nvim
|
2022-03-02 00:50:21 -06:00
|
|
|
export MANPAGER="nvim +Man!"
|
2022-01-08 15:24:29 -06:00
|
|
|
else
|
|
|
|
export EDITOR=vim
|
|
|
|
export VISUAL=vim
|
|
|
|
fi
|
|
|
|
|
|
|
|
### Terminal Specific Configuration ###
|
|
|
|
# If using the kitty terminal we want to set our TERM var to be xterm as kitty will send
|
|
|
|
# kitty-xterm which causes a fucking headache and a half due to ncurses not containing
|
|
|
|
# that by default
|
|
|
|
if [[ "${TERM}" = *"xterm-kitty"* ]]; then
|
2022-01-09 00:34:43 -06:00
|
|
|
alias ssh="TERM=xterm-256color ssh"
|
2022-02-20 03:01:51 -06:00
|
|
|
alias icat="kitty +kitten icat"
|
2022-01-08 15:24:29 -06:00
|
|
|
__kitty_complete
|
|
|
|
fi
|
|
|
|
|
|
|
|
### Zsh Vi-Mode Configuration ###
|
|
|
|
|
|
|
|
# Makes the cursor change based on the mode
|
|
|
|
export VI_MODE_SET_CURSOR=true
|
|
|
|
# Set the editor to neovim for visual mode
|
|
|
|
export ZVM_VI_EDITOR="${EDITOR}"
|
|
|
|
# This ensures that fzf completion works
|
2022-02-20 02:20:29 -06:00
|
|
|
zvm_after_init_commands+=('[[ -r ~/.fzf.zsh ]] && source ~/.fzf.zsh')
|
2022-01-08 15:24:29 -06:00
|
|
|
|
|
|
|
### Aliases ###
|
|
|
|
|
|
|
|
## Exa ls Replacement Configuration ##
|
|
|
|
if which exa >/dev/null 2>&1; then
|
|
|
|
alias ls="exa --icons --group"
|
|
|
|
alias l="exa --icons --group -alh"
|
|
|
|
alias tree="ls --tree"
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Git Aliases ##
|
|
|
|
if which git >/dev/null 2>&1; then
|
2022-01-21 05:51:07 -06:00
|
|
|
alias gc="git commit"
|
|
|
|
alias gcm="git commit -m"
|
2022-01-08 15:24:29 -06:00
|
|
|
alias ga="git add"
|
|
|
|
alias gp="git push"
|
|
|
|
alias gb="git branch"
|
|
|
|
alias gco="git checkout"
|
|
|
|
alias gpl="git pull"
|
|
|
|
alias gs="git status"
|
2022-02-21 14:25:20 -06:00
|
|
|
alias gst="git stash"
|
|
|
|
alias gstc="git stash clear"
|
2022-01-23 16:52:02 -06:00
|
|
|
alias gsw="git switch"
|
2022-01-08 15:24:29 -06:00
|
|
|
alias gd="git diff"
|
|
|
|
alias gr="git remote"
|
2022-02-15 13:21:19 -06:00
|
|
|
alias gl="git log"
|
|
|
|
alias gw="git worktree"
|
2022-03-17 15:34:22 -05:00
|
|
|
alias gwa="git worktree add"
|
|
|
|
alias gwr="git worktree remove"
|
2022-01-08 15:24:29 -06:00
|
|
|
alias git-remote="git config --get remote.origin.url"
|
2022-03-17 15:34:22 -05:00
|
|
|
alias gbc="git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'"
|
2022-01-08 15:24:29 -06:00
|
|
|
fi
|
|
|
|
|
2022-03-17 15:34:22 -05:00
|
|
|
gbf() {
|
|
|
|
local remote
|
|
|
|
local default_branch
|
|
|
|
remote="${1:=origin}"
|
|
|
|
default_branch="$(git remote show "${remote}" | awk '/HEAD branch/ {print $NF}')"
|
|
|
|
git fetch "${remote}" "${default_branch}":"${default_branch}"
|
|
|
|
}
|
2022-01-08 15:24:29 -06:00
|
|
|
## Mac Specific Aliases ##
|
|
|
|
if [[ "${OSTYPE}" = "darwin"* ]]; then
|
|
|
|
alias c="pbcopy"
|
|
|
|
alias p="pbpaste"
|
|
|
|
alias grep="ggrep"
|
|
|
|
alias find="gfind"
|
|
|
|
alias kill="gkill"
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Neovim Aliases ##
|
|
|
|
if which nvim >/dev/null 2>&1; then
|
|
|
|
alias n="nvim"
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Bat (Alternative to Cat) Aliases ##
|
|
|
|
if which bat >/dev/null 2>&1; then
|
|
|
|
alias cat="bat"
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Misc Aliases ##
|
|
|
|
alias ghidra="ghidraRun"
|
|
|
|
alias v="vim"
|
|
|
|
alias :q="exit"
|
|
|
|
alias Get-Public-IPV4="dig @resolver4.opendns.com myip.opendns.com +short -4"
|
|
|
|
alias Get-Public-IPV6="dig @resolver1.ipv6-sandbox.opendns.com AAAA myip.opendns.com +short -6"
|
2022-02-21 23:04:53 -06:00
|
|
|
alias :profile="${EDITOR} ${HOME}/.profile"
|
2022-01-08 15:24:29 -06:00
|
|
|
|
|
|
|
### Completions ###
|
|
|
|
|
|
|
|
# Homebrew completions
|
|
|
|
if type brew &>/dev/null; then
|
|
|
|
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
|
|
|
|
|
|
|
|
autoload -Uz compinit
|
|
|
|
compinit
|
|
|
|
fi
|
|
|
|
|
2022-01-09 00:27:14 -06:00
|
|
|
# Completions from .zsh directory
|
|
|
|
if [[ -d "${HOME}/.zsh/completions" ]]; then
|
|
|
|
FPATH="${HOME}/.zsh/completions:${FPATH}"
|
|
|
|
|
|
|
|
autoload -Uz compinit
|
|
|
|
compinit
|
|
|
|
fi
|
|
|
|
|
2022-01-08 15:24:29 -06:00
|
|
|
### Functions ###
|
2022-02-15 13:31:47 -06:00
|
|
|
del() {
|
|
|
|
local BASE_TRASH_DIR
|
|
|
|
BASE_TRASH_DIR="${HOME}/.Trash/"
|
|
|
|
|
|
|
|
local trash_del_dir
|
|
|
|
trash_del_dir="${BASE_TRASH_DIR}/del-$(date +%Y-%m-%dT%H:%M:%S)"
|
|
|
|
|
|
|
|
mkdir -p "${trash_del_dir}"
|
|
|
|
|
|
|
|
for i in "${@}"; do
|
|
|
|
mv "${i}" "${trash_del_dir}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-02-21 14:25:20 -06:00
|
|
|
DAP-Python-Gen() {
|
|
|
|
local module
|
|
|
|
module="${1}"
|
|
|
|
name="${2:=Local Module}"
|
2022-03-02 00:50:21 -06:00
|
|
|
|
2022-02-21 14:25:20 -06:00
|
|
|
mkdir -p .vscode
|
2022-03-02 00:50:21 -06:00
|
|
|
cat <<__EOF__ >.vscode/launch.json
|
2022-02-21 14:25:20 -06:00
|
|
|
{
|
|
|
|
"configurations": [
|
|
|
|
{
|
|
|
|
"name": "Launch ${name}",
|
|
|
|
"type": "python",
|
|
|
|
"request": "launch",
|
|
|
|
"module": "${module}"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
__EOF__
|
|
|
|
}
|
|
|
|
|
2022-01-14 12:02:52 -06:00
|
|
|
Note() {
|
2022-02-01 15:21:25 -06:00
|
|
|
local invoked_dir
|
|
|
|
invoked_dir="$(pwd)"
|
|
|
|
|
2022-01-14 12:02:52 -06:00
|
|
|
mkdir -p "${NOTES_DIR}"
|
|
|
|
|
2022-01-15 10:00:44 -06:00
|
|
|
if [ -z "${1}" ]; then
|
2022-01-21 05:17:57 -06:00
|
|
|
printf "%s\n" "No note provided!" 1>&2
|
2022-01-15 10:00:44 -06:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2022-01-14 12:02:52 -06:00
|
|
|
local note_selection
|
|
|
|
note_selection="${NOTES_DIR}/${2}.norg"
|
|
|
|
|
2022-01-21 05:17:57 -06:00
|
|
|
local note_bare
|
|
|
|
note_bare="${2}"
|
|
|
|
|
|
|
|
local selection
|
|
|
|
selection="${1}"
|
|
|
|
|
|
|
|
local option_selected
|
|
|
|
option_selected=1
|
2022-02-15 13:21:19 -06:00
|
|
|
while ((option_selected != 0)); do
|
2022-01-21 05:17:57 -06:00
|
|
|
case "${selection}" in
|
|
|
|
--open | -o)
|
|
|
|
if [[ -z "${note_bare}" ]]; then
|
|
|
|
echo_rgb "No note selection provided!" 255 0 0 25 0 0
|
|
|
|
return 1
|
|
|
|
fi
|
2022-02-01 15:21:25 -06:00
|
|
|
cd "${NOTES_DIR}"
|
2022-01-21 05:17:57 -06:00
|
|
|
nvim "${note_selection}"
|
2022-02-01 15:21:25 -06:00
|
|
|
cd "${invoked_dir}"
|
2022-01-21 05:17:57 -06:00
|
|
|
option_selected=0
|
|
|
|
;;
|
|
|
|
--delete | -d)
|
2022-02-01 15:21:25 -06:00
|
|
|
if [[ -z "${*:2}" ]]; then
|
|
|
|
echo_rgb "No note selection provided!" 255 0 0 25 0 0 1>&2
|
2022-01-21 05:17:57 -06:00
|
|
|
return 1
|
|
|
|
fi
|
2022-02-01 15:21:25 -06:00
|
|
|
local exit_code
|
|
|
|
exit_code=0
|
|
|
|
for note in "${@:2}"; do
|
|
|
|
note_selection="${NOTES_DIR}/${note}.norg"
|
|
|
|
if [[ ! -r "${note_selection}" ]]; then
|
|
|
|
echo_rgb "Could not delete \"${note}\", does it exist?" 255 0 0 25 0 0 1>&2
|
|
|
|
exit_code=1
|
|
|
|
fi
|
|
|
|
rm -f "${note_selection}"
|
|
|
|
done
|
2022-01-21 05:17:57 -06:00
|
|
|
option_selected=0
|
2022-02-01 15:21:25 -06:00
|
|
|
return "${exit_code}"
|
2022-01-21 05:17:57 -06:00
|
|
|
;;
|
|
|
|
--list | -l)
|
|
|
|
for note in "${NOTES_DIR}/"*.norg; do
|
|
|
|
echo_rgb "${note}" 64 143 255 11 22 36
|
|
|
|
done
|
|
|
|
option_selected=0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
selection="--open"
|
|
|
|
note_selection="${NOTES_DIR}/${1}.norg"
|
|
|
|
note_bare="${1}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2022-01-14 12:02:52 -06:00
|
|
|
}
|
2022-01-08 15:24:29 -06:00
|
|
|
|
|
|
|
TCPDump-Capture() {
|
|
|
|
tcpdump -qns 0 -X -r "${1}"
|
|
|
|
}
|
|
|
|
|
|
|
|
Known-Hosts() {
|
|
|
|
local prev_ifs
|
|
|
|
prev_ifs="${IFS}"
|
|
|
|
while IFS=$'\n' read -r line; do
|
|
|
|
echo "${line}" | cut -d " " -f1
|
|
|
|
done <~/.ssh/known_hosts
|
|
|
|
IFS="${prev_ifs}"
|
|
|
|
}
|
|
|
|
|
|
|
|
Work-Hours() {
|
|
|
|
local WORK_HOURS_PATH
|
|
|
|
WORK_HOURS_PATH=~/Vircio/Work-Hours
|
|
|
|
mkdir -p "${WORK_HOURS_PATH}"
|
|
|
|
${EDITOR} "${WORK_HOURS_PATH}/$(date +%Y-%m-%d)"
|
|
|
|
}
|
|
|
|
|
|
|
|
date_iso_8601() {
|
|
|
|
date +%Y-%m-%dT%H:%M:%S
|
|
|
|
}
|
|
|
|
|
|
|
|
echo_rgb() {
|
|
|
|
# Echo a colored string to the terminal based on rgb values
|
|
|
|
#
|
|
|
|
# NOTE: This function will only truly work with terminals that support TRUE COLOR, see:
|
|
|
|
# https://gist.github.com/XVilka/8346728
|
|
|
|
#
|
|
|
|
# Positional Arguments:
|
|
|
|
#
|
|
|
|
# message <type: string> <position: 1> <required: true>
|
|
|
|
# - The message to be printed to stdout
|
|
|
|
# red <type: int> <position: 2> <required: true>
|
|
|
|
# - The red value from 0 to 255
|
|
|
|
# green <type: int> <position: 3> <required: true>
|
|
|
|
# - The green value from 0 to 255
|
|
|
|
# blue <type: int> <position: 4> <required: true>
|
|
|
|
# - The blue value from 0 to 255
|
|
|
|
# bg_red <type: int> <position: 5> <required: false>
|
|
|
|
# - The background red value from 0 to 255
|
|
|
|
# bg_green <type: int> <position: 6> <required: false>
|
|
|
|
# - The background green value from 0 to 255
|
|
|
|
# bg_blue <type: int> <position: 7> <required: false>
|
|
|
|
# - The background blue value from 0 to 255
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# echo_rgb "Yep" 10 80 30
|
|
|
|
# echo_rgb "DESTROY MY EYES" 255 0 255 0 255 0
|
|
|
|
#
|
|
|
|
# POSIX Compliant:
|
|
|
|
# N/A
|
|
|
|
#
|
|
|
|
|
|
|
|
local red
|
|
|
|
local green
|
|
|
|
local blue
|
|
|
|
local input
|
|
|
|
|
|
|
|
local bg_red
|
|
|
|
local bg_green
|
|
|
|
local bg_blue
|
|
|
|
|
|
|
|
input="${1}"
|
|
|
|
red="${2}"
|
|
|
|
green="${3}"
|
|
|
|
blue="${4}"
|
|
|
|
bg_red="${5}"
|
|
|
|
bg_green="${6}"
|
|
|
|
bg_blue="${7}"
|
|
|
|
|
|
|
|
for num in "${@:2}"; do
|
|
|
|
[[ ! "${num}" =~ [0-9] ]] &&
|
2022-01-21 05:17:57 -06:00
|
|
|
printf "%s\n" "Given RGB value was not a number, received ${num}" 1>&2 &&
|
2022-01-08 15:24:29 -06:00
|
|
|
return 1
|
|
|
|
[[ "${num}" -gt 255 ]] &&
|
2022-01-21 05:17:57 -06:00
|
|
|
printf "%s\n" "Given RGB value must be less than 255, received ${num}" 1>&2 &&
|
2022-01-08 15:24:29 -06:00
|
|
|
return 1
|
|
|
|
[[ "${num}" -lt 0 ]] &&
|
2022-01-21 05:17:57 -06:00
|
|
|
printf "%s\n" "Given RGB value must be more than 0, received ${num}" 1>&2 &&
|
2022-01-08 15:24:29 -06:00
|
|
|
return 1
|
|
|
|
done
|
|
|
|
|
2022-01-21 05:17:57 -06:00
|
|
|
if [ -t 1 ]; then
|
|
|
|
if [ -n "${5}" ]; then
|
|
|
|
[[ -z "${6}" ]] && echo "A value must be passed for bg_green" && return 1
|
|
|
|
[[ -z "${7}" ]] && echo "A value must be passed for bg_blue" && return 1
|
|
|
|
printf "\033[38;2;%s;%s;%s;48;2;%s;%s;%sm%s\033[m\n" \
|
|
|
|
"${red}" "${green}" "${blue}" "${bg_red}" "${bg_green}" "${bg_blue}" "${input}"
|
|
|
|
else
|
|
|
|
printf "\033[0;38;2;%s;%s;%sm%s\033[m\n" "${red}" "${green}" "${blue}" "${input}"
|
|
|
|
fi
|
2022-01-08 15:24:29 -06:00
|
|
|
else
|
2022-01-21 05:17:57 -06:00
|
|
|
printf "%s\n" "${input}"
|
2022-01-08 15:24:29 -06:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
chr() {
|
|
|
|
python3 -c "print(chr(int('${1}')))"
|
|
|
|
}
|
|
|
|
|
|
|
|
ord() {
|
|
|
|
python3 -c "print(ord('${1}'))"
|
|
|
|
}
|
2022-01-14 01:40:44 -06:00
|
|
|
|
2022-03-02 00:50:21 -06:00
|
|
|
tmp() {
|
2022-02-26 16:13:06 -06:00
|
|
|
(
|
2022-03-02 00:50:21 -06:00
|
|
|
export MY_SHLVL=tmp:$MY_SHLVL
|
|
|
|
export od=$PWD
|
|
|
|
tmp=$(mktemp -d)
|
2022-02-26 16:13:06 -06:00
|
|
|
export tmp
|
|
|
|
trap 'rm -rf ${tmp}' 0
|
|
|
|
if ! cd "${tmp}"; then
|
|
|
|
printf "%s \"%s\"\n" "Unable to cd into" "${tmp}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-03-02 00:50:21 -06:00
|
|
|
if [ -z "$1" ]; then
|
2022-02-26 16:13:06 -06:00
|
|
|
$SHELL -l
|
|
|
|
else
|
|
|
|
[ "$1" = "-l" ] && {
|
|
|
|
shift
|
|
|
|
set "${@}" ";" "$SHELL -l"
|
|
|
|
}
|
|
|
|
eval "${@}"
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-17 18:33:57 -05:00
|
|
|
cdl() {
|
|
|
|
if [[ -f "${1}" ]]; then
|
|
|
|
cd "$(dirname "$(readlink -f "${1}")")"
|
|
|
|
else
|
|
|
|
echo_rgb "No such file: ${1}" 255 0 0 30 0 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-01-14 01:40:44 -06:00
|
|
|
### FZF FUNCTIONS ###
|
|
|
|
killer() {
|
|
|
|
(
|
|
|
|
date
|
|
|
|
ps -ef
|
|
|
|
) |
|
|
|
|
fzf --bind='ctrl-r:reload(date; ps -ef)' \
|
|
|
|
--header=$'Press CTRL-R to reload\n\n' --header-lines=2 \
|
|
|
|
--preview='echo {}' --preview-window=down,3,wrap \
|
|
|
|
--layout=reverse --height=80% | awk '{print $2}' | xargs kill -9
|
|
|
|
}
|