aboutsummaryrefslogtreecommitdiff
path: root/shell/utils
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2021-09-05 00:23:41 -0400
committerMitchell Riedstra <mitch@riedstra.dev>2021-09-05 00:23:41 -0400
commit27ac56f3af62474cb4e69728541e551c0c5dd4a4 (patch)
tree4fece6e169320bdfa8b2fc90fc629285520fcb0f /shell/utils
parent319ac2aec7787ae500eb3ff84020b7ca3e149298 (diff)
downloaddotfiles-27ac56f3af62474cb4e69728541e551c0c5dd4a4.tar.gz
dotfiles-27ac56f3af62474cb4e69728541e551c0c5dd4a4.tar.xz
Major updates to my shell configuration
Diffstat (limited to 'shell/utils')
-rw-r--r--shell/utils267
1 files changed, 0 insertions, 267 deletions
diff --git a/shell/utils b/shell/utils
deleted file mode 100644
index a68b640..0000000
--- a/shell/utils
+++ /dev/null
@@ -1,267 +0,0 @@
-# E.g. after `.mkshrc` is called, perhaps in `~/.mkshrc.local`
-# export GOPATH=$HOME/code/gopath
-# export GOROOT=$HOME/go/1.13.5
-# set_go
-set_go() {
- export GOPATH="${GOPATH:-$HOME/go}"
- export PATH="$GOPATH/bin:$PATH"
-
- GOROOT="${GOROOT:-/usr/local/go}"
- _gobin="${GOROOT}/bin"
- if [ -e "$_gobin" ] ; then
- export PATH="$_gobin:$PATH"
- fi
-}
-_set_editor() {
- export EDITOR="$1"
- export VISUAL="$1"
- alias vi="$EDITOR"
- alias vim="$EDITOR"
- alias edit="$EDITOR"
- alias e="$EDITOR"
-}
-set_editor() {
- for editor in vim vi ed ; do
- unalias "$editor" >/dev/null 2>&1
- e="$(command -v "$editor")"
- if [ -n "$e" ] && [ -x "$e" ] ; then
- _set_editor "$e"
- fi
- break
- done
-}
-set_pager() {
- #shellcheck disable=SC2155
- export PAGER="$(command -v cat more less 2>/dev/null | tail -n1)"
-}
-set_lang() {
-export CHARSET="$1";
-export LANG="$1";
-}
-
-# Usage debugstarttls $ipaddr:$port
-debugstarttls() {
- openssl s_client -starttls smtp -crlf -connect "$1" "$2"
-}
-
-randmacgen() {
- if [ "$(uname)" = "FreeBSD" ] ; then
- LC_COLLATE=c
- fi
- tr -c -d '0123456789abcdef' < /dev/urandom \
- | head -c 12 \
- | sed 's!^M$!!;s!\-!!g;s!\.!!g;s!\(..\)!\1:!g;s!:$!!'
- echo ""
-}
-# First argument is the interface on which to scan
-ipv6_local_hosts() {
-if [ -n "$1" ] ; then
- interface="$1"
- ping6 -c 3 "ff02::2%$interface" \
- | grep 'bytes from' \
- | awk '{print $4}' \
- | sort \
- | uniq \
- | sed -e's/:$//'
-else
- echo "You need to specify an interface"
-fi
-}
-set_nocaps() {
- setxkbmap -layout "us,de"
- setxkbmap -option ctrl:nocaps
- setxkbmap -option shift:breaks_caps
- setxkbmap -option numpad:microsoft
- setxkbmap -option grp:alt_space_toggle
-}
-# Usage: dir_oct:file_oct path
-setperms() {
- _perm="$1"; shift
- dir_perms=$(echo "$_perm" | awk -F: '{print $1}')
- file_perms=$(echo "$_perm" | awk -F: '{print $2}')
- find "$@" -type f -print0 | xargs -0 chmod "$file_perms"
- find "$@" -type d -print0 | xargs -0 chmod "$dir_perms"
-}
-
-set_title() {
- printf $'\033]0;'"%s"$'\007' "$1"
-}
-
-set_my_title() {
- _load="Load Avg: $(_sys_load)"
- _free_mem="M Free: $(_sys_memory)"
- _uptime="Uptime: $(_sys_uptime)"
- set_title "$(id -un)[$(hostname)] -- $_load $_free_mem $_uptime"
-}
-
-_sys_memory() {
- ! [ -e "$(command -v vmstat)" ] && return
- if [ "$(uname)" = "Linux" ] ; then
- vmstat | tail -n1 | awk '{print $4/1024}' | sed -e's/\..*$//g'
- elif [ "$(uname)" = "FreeBSD" ] ; then
- vmstat | tail -n1 | awk '{print $5/1024}' | sed -e's/\..*$//g'
- elif [ "$(uname)" = "OpenBSD" ] ; then
- vmstat | sed -n '$p' | awk '{print $4}' | sed 's/M$//'
- fi
-}
-
-_sys_load() {
- # Works on BSD too, neat.
- uptime | sed -E 's/^.*load averages?: ([0-9]+\.[0-9]+).*$/\1/g'
-}
-
-_sys_uptime() {
- # Took awhile to figure out, but this works on BSD as well
- uptime | sed -E -e's/^.*up[ ]+//g' -e's/^([^,]*),.*/\1/g' -e's/^([^ ]+)[ ]*(.).*/\1\2/g'
-}
-
-
-timestamp() {
- date +%m.%d.%y_%H.%M.%S
-}
-
-checkSSHAgent() {
- ssh_agent_conf="$HOME/.ssh/agent"
- if [ -e "$ssh_agent_conf" ] ; then
- #shellcheck disable=SC1090
- . "$ssh_agent_conf"
- fi
- #shellcheck disable=SC2009
- if ! ps -eo pid | grep -q "$SSH_AGENT_PID" \
- || ! [ -e "$ssh_agent_conf" ] \
- || [ -z "$SSH_AGENT_PID" ] ; \
- then
- ssh-agent -s | grep -v echo > "$ssh_agent_conf"
- #shellcheck disable=SC1090
- . "$ssh_agent_conf"
- fi
-}
-
-checkSSHAgentGPG() {
- export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
-}
-
-passenv() {
- _f="$(mktemp)"
- pass "$@" > "$_f"
- #shellcheck disable=SC1090
- . "$_f"
- rm -f "$_f"
-}
-
-
-######################################################################
-# Tmux utilities
-_tmux_session() {
-session=""
-window_name=""
-working_directory="$(pwd)"
-while [ $# -gt 0 ] ; do case $1 in
---) shift ; break;;
--s) session="$2" ; shift ; shift ;;
--n) window_name="$2" ; shift ; shift ;;
--w) working_directory="$2" ; shift ; shift ;;
-*)echo "Invalid option $1" ; return ;;
-esac ; done
-
-cd "$working_directory" || { echo "Cannot change to: $working_directory" ; return; }
-
-tmux new-session -s "$session" -n "$window_name" -c "$working_directory" \;\
- "$@"
-}
-
-
-_tmux_dev() {
-session=""
-working_directory="$(pwd)"
-window_name="editor"
-while [ $# -gt 0 ] ; do case $1 in
---) shift ; break;;
--s) session="$2" ; shift ; shift ;;
--n) window_name="$2" ; shift ; shift ;;
--w) working_directory="$2" ; shift ; shift ;;
-*)echo "Invalid option $1" ; return ;;
-esac ; done
-
-cd "$working_directory" || { echo "Cannot change to: $working_directory" ; return; }
-
-_tmux_session -s "$session" -w "$working_directory" -n "$window_name" \
- -- \
- send-keys -t 0 "$EDITOR" \; send-keys -t 0 Enter \;\
- new-window -n "shell" \;\
- new-window -n "git" \;\
- send-keys -t 0 "git status" \; send-keys -t 0 Enter \;\
- "$@"
-
-}
-
-_tmux_servers_split_commands() {
-n=0
-server_cmds=""
-while [ $# -gt 0 ] ; do
- if [ $n -eq 0 ] ; then
- server_cmds='send-keys "ssh \"'"$1"'\"" \; send-keys Enter \; '
- else
- server_cmds="${server_cmds} split-window \; "'send-keys "ssh \"'"$1"'\"" \; send-keys Enter \; '
- fi
- n="$(echo "$n+1" | bc)"
- shift
-done
-echo "$server_cmds"
-}
-
-_tmux_servers() {
-session=""
-working_directory="$HOME"
-servers=""
-layout="even-vertical"
-while [ $# -gt 0 ] ; do case $1 in
---) shift ; break;;
--s) session="$2" ; shift ; shift ;;
--w) working_directory="$2" ; shift ; shift ;;
--servers) servers="$2"; shift ; shift ;;
--l) layout="$2"; shift ; shift ;;
-*)echo "Invalid option $1" ; return ;;
-esac ; done
-cd "$working_directory" || { echo "Cannot change to: $working_directory" ; return; }
-
-layout="select-layout $layout ';' set-window-option synchronize-panes on ';'"
-
-eval _tmux_session -s "\$session" -w "\$working_directory" -n "main" \
- -- \
- $(_tmux_servers_split_commands $servers) \
- "$layout" \
- "\$@" \
-
-}
-
-gitdate() {
- date=""
- while [ $# -gt 0 ] ; do case $1 in
- -d) date="$2" ; shift ; shift ;;
- *) printf "Bad option: $1... usage:\n$0 -d \"\$date_string\"\n" ; return ;;
- esac ; done
-
- date="$(date --date "$date")"
-
- export GIT_AUTHOR_DATE="$date"
- export GIT_COMMITTER_DATE="$date"
- echo export GIT_AUTHOR_DATE="$date"
- echo export GIT_COMMITTER_DATE="$date"
-}
-
-gitdateUnset() {
- unset GIT_AUTHOR_DATE
- unset GIT_COMMITTER_DATE
-}
-
-gpgTmpDir() {
- set -x
- if echo "$GNUPGHOME" | grep -q "/dev/shm/"; then
- rm -rvf "$GNUPGHOME"
- fi
-
- #shellcheck disable=SC2155
- export GNUPGHOME="$(mktemp -d /dev/shm/GPG.XXXXXX)"
- set +x
-}