Sync minimal branch with master files.

This commit is contained in:
Darren 'Tadgy' Austin 2023-09-29 19:21:25 +01:00
commit eca63b736d
13 changed files with 376 additions and 147 deletions

View file

@ -15,11 +15,8 @@ fi
hash ssh-add ssh-agent >/dev/null 2>&1 && {
# Stop any started ssh-agent as long as the shell level is 1 and we're not on a tty.
(( SHLVL == 1 )) && [[ "$(tty)" == /dev/pts/* ]] && [[ -n "$SSH_AGENT_PID" ]] && {
eval "$(ssh-agent -k)"
(( $? != 0 )) && printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to stop ssh-agent." >&2
sleep 5
unset SSH_AGENT_PID SSH_AUTH_SOCK
(( SHLVL == 1 )) && [[ "$(tty)" != /dev/tty* ]] && [[ -n "$SSH_AGENT_PID" ]] && {
eval "$(ssh-agent -k >/dev/null 2>&1)" >/dev/null || printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to stop ssh-agent." >&2
}
# Update the ~/.ssh/agents file.

View file

@ -1,12 +1,14 @@
#!/bin/bash - not strictly necessary, but helps nano with syntax highlighting.
# Source bash specific set up,
[[ -f ~/.bashrc ]] && . ~/.bashrc
[[ -f "$HOME/.bashrc" ]] && . "$HOME/.bashrc"
# Environment.
export EDITOR="nano"
export LANG="en_GB.UTF-8"
export LC_COLLATE="POSIX" # 'C' causes issues with some applications
# export LC_CTYPE="POSIX" # Not sure why I set this in the first place...
export LESS="-RM -j.5 -i -PM?f%F:stdin. -- Page %dt of %D -- %lt/%L (%Pt\%)$"
export LESS="-RM -j.5 -i -PM'?f%F:stdin. -- Page %dt of %D -- %lt/%L (%Pt\%)$'"
export PAGER="less"
export PATH="/opt/sbin:/usr/local/sbin:/usr/sbin:/sbin:$PATH"
export VISUAL="$EDITOR"
@ -15,23 +17,33 @@ hash lesspipe >/dev/null 2>&1 && eval "$(SHELL=/bin/sh lesspipe)"
# Platform specific set up.
PLATFORM="$(uname -s)"
if [[ "$PLATFORM" = "Linux" ]]; then
# This is a hack to work around a problem with elogind/pam not creating
# a gnupg directory under /run/user/0 for the gpg-agent socket.
(( $(id -u) == 0 )) && [[ -e "$HOME/.gnupg/S.gpg-agent" ]] && mkdir -m 700 -p /run/user/0/gnupg && ln -sf "$HOME/.gnupg/S.gpg-agent" /run/user/0/gnupg
export GPG_TTY="$(tty)" && gpg-connect-agent updatestartuptty /bye >/dev/null 2>&1
# shellcheck disable=SC2155
export GPG_TTY="$(tty)"
export I_WANT_A_BROKEN_PS=1
export LYNX_CFG="$HOME/.lynx.cfg"
export LYNX_LSS="$HOME/.lynx.lss"
export MANPAGER="less"
export MANPATH="$HOME/.local/share/man:$MANPATH"
hash dircolors >/dev/null 2>&1 && eval "$(dircolors -b ~/.dir_colors)"
hash dircolors >/dev/null 2>&1 && eval "$(dircolors -b "$HOME/.dir_colors")"
hash gpgconf >/dev/null 2>&1 && {
GPG_SOCK_DIR="$(gpgconf --list-dirs | awk -F : '/socketdir:/ { print $2 }')"
# shellcheck disable=SC2174
[[ ! -e "$GPG_SOCK_DIR" ]] && mkdir -m 700 -p "$GPG_SOCK_DIR"
[[ ! -e "$GPG_SOCK_DIR/S.gpg-agent" ]] && [[ -e "$HOME/.gnupg/S.gpg-agent" ]] && ln -sf "$HOME/.gnupg/S.gpg-agent" "$GPG_SOCK_DIR"/
unset GPG_SOCK_DIR
}
hash gpg-connect-agent >/dev/null 2>&1 && gpg-connect-agent updatestartuptty /bye >/dev/null 2>&1
[[ ! -e "$HOME/.config/lxterminal/lxterminal.conf" ]] && (
cd "$HOME/.config/lxterminal"
[[ -e "lxterminal.conf-${HOSTNAME%%.*}" ]] && ln -sf "lxterminal.conf-${HOSTNAME%%.*}" "lxterminal.conf"
)
elif [[ "$PLATFORM" = "Darwin" ]]; then
export LSCOLORS="ExGxdxdxCxDxDxbcacbeae"
export MANPAGER="less -Mis -PM'Page %dt$'"
export MANPATH="/opt/local/share/man:$MANPATH"
export PATH="/opt/local/sbin:/opt/local/bin:$PATH"
else
echo "${BASH_SOURCE##*/}: unsupported platform: $PLATFORM" >&2
printf "%s: %s\\n" "${BASH_SOURCE##*/}" "unsupported platform: $PLATFORM" >&2
fi
unset PLATFORM
@ -46,46 +58,44 @@ hash screen >/dev/null 2>&1 && {
export SCREENDIR="$HOME/.screen-${HOSTNAME%%.*}"
if [[ -n "$SSH_TTY" ]]; then
if [[ -n "$STY" ]]; then
echo "Screen $STY, window $WINDOW."
echo
# shellcheck disable=SC2154
printf "%s\\n\\n" "Screen $STY, window $WINDOW."
else
SCREENS="$(screen -ls | grep '[[:alpha:]]' | grep -E -v '^([[:digit:]]+|No) Socket(s)?')"
if [[ -n "$SCREENS" ]]; then
echo "$SCREENS"
echo
printf "%s\\n\\n" "$SCREENS"
else
echo "No screens."
echo
printf "%s\\n\\n" "No screens."
fi
unset SCREENS
fi
elif [[ -n "$STY" ]]; then
echo "Screen $STY, window $WINDOW."
echo
# shellcheck disable=SC2154
printf "%s\\n\\n" "Screen $STY, window $WINDOW."
else
TTY="$(tty | cut -d/ -f3-)"
SCREENS="$(screen -list | grep -F "${HOSTNAME%%.*}" | grep -F "${TTY//\//-}")"
case "$(echo ${SCREENS:--n} | wc -l)" in
SCREENS="$(screen -ls | grep -F "${HOSTNAME%%.*}" | grep -F "${TTY//\//-}")"
# This has to be an echo, not printf.
case "$(echo "${SCREENS:--n}" | wc -l)" in
0)
# No screens found - start a new instance, if on a tty.
[[ "$TTY" == *tty* ]] && sleep 1 && screen
# No screens found - start a new instance if on a tty.
[[ "$TTY" == tty* ]] && screen
;;
1)
# Just one screen - reconnect if it's not dead.
if (( $(echo "$SCREENS" | grep "Dead" | wc -l) == 1 )); then
echo "Found dead screen for $TTY:"
echo "$SCREENS" | sed -e 's/^/ /g'
if (( $(printf "%s" "$SCREENS" | grep -c -F 'Dead') == 1 )); then
printf "%s:\\n" "Found dead screen for $TTY"
printf "%s\\n" "$SCREENS" | sed -e 's/^/ /g'
else
sleep 1
screen -dr "${TTY//\//-}.${HOSTNAME%%.*}"
fi
;;
*)
# Multiple screens - output a list
echo "Multiple screens found for $TTY:"
echo "$SCREENS" | sed -e 's/^/ /g'
printf "%s:\\n" "Multiple screens found for $TTY"
printf "%s\\n" "$SCREENS" | sed -e 's/^/ /g'
;;
esac
unset SCREENS
fi
unset SCREENS TTY
}

226
.bashrc
View file

@ -1,50 +1,58 @@
#!/bin/bash - not strictly necessary, but helps nano with syntax highlighting.
__find_ssh_agent_sock() {
# Returns: 0 = Found an alternative socket.
# Find an *active* ssh agent socket.
# Returns: 0 = Found an active socket.
# 1 = Did not find a viable socket.
local ERR I
local I
# Search the SSH_AUTH_SOCKS array for a viable socket.
for ((I = 0; I < ${#SSH_AUTH_SOCKS[@]}; I++)); do
[[ "${SSH_AUTH_SOCKS[$I]}" =~ ^[[:blank:]]*$ ]] && continue
SSH_AUTH_SOCK="${SSH_AUTH_SOCKS[$I]}" ssh-add -l >/dev/null 2>&1
(( $? < 2 )) && { export SSH_AUTH_SOCK="${SSH_AUTH_SOCKS[$I]}"; break; }
(( $? <= 1 )) && {
export SSH_AUTH_SOCK="${SSH_AUTH_SOCKS[$I]}"
return 0
}
unset SSH_AUTH_SOCK
done
[[ -z "$SSH_AUTH_SOCK" ]] && return 1
return 0
return 1
}
__read_ssh_agents() {
# Read all the known ssh agent sockets into an array.
# Returns: 0 = Processed and read the agents file without issue.
# 1 = Error processing/read the agents file.
local ERR FD I SOCK
# 1 = Error processing/reading the agents file.
local ERR FD I PLATFORM SOCK
[[ ! -e ~/.ssh/agents ]] && touch ~/.ssh/agents
[[ ! -e "$HOME/.ssh/agents" ]] && touch "$HOME/.ssh/agents"
# Determine the platform being logged into.
PLATFORM="$(uname -s)"
# Lock the ~/.ssh/agents file.
if [[ "$(uname -s)" == "Linux" ]]; then
if [[ "$PLATFORM" == "Linux" ]]; then
# Linux has 'flock', thankfully.
{ exec {FD}<~/.ssh/agents && flock -E 10 -e -w 0.5 "$FD"; } || {
exec {FD}<"$HOME/.ssh/agents" && flock -E 10 -e -w 0.5 "$FD"
ERR=$?
if (( ERR == 10 )); then
printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to obtain lock on ~/.ssh/agents." >&2
else
printf "\\033[1;31;40m%s\\033[0;39m\\n" "Flock usage error." >&2
fi
return 1
}
elif (( ERR > 0 )); then
printf "\\033[1;31;40m%s\\033[0;39m\\n" "Flock usage error." >&2
return 1
fi
# Make note of the mtime for use in write_ssh_agents.
SSH_AGENTS_MTIME="$(stat --format=%.9Y ~/.ssh/agents)"
elif [[ "$(uname -s)" == "Darwin" ]]; then
SSH_AGENTS_MTIME="$(stat --format=%.9Y "$HOME/.ssh/agents")"
elif [[ "$PLATFORM" == "Darwin" ]]; then
# Do locking the sucky way on macOS.
for ((I = 0; I < 6; I++)); do
if shlock -p "$$" -f ~/.ssh/agents.lock; then
exec {FD}<~/.ssh/agents
for ((I = 0; I <= 5; I++)); do
if shlock -p "$$" -f "$HOME/.ssh/agents.lock"; then
exec {FD}<"$HOME/.ssh/agents"
# Make note of the mtime for use in write_ssh_agents.
SSH_AGENTS_MTIME="$(stat -f %Fm ~/.ssh/agents)"
SSH_AGENTS_MTIME="$(stat -f %Fm "$HOME/.ssh/agents")"
ERR=0
break
else
@ -52,33 +60,41 @@ __read_ssh_agents() {
sleep 0.1
fi
done
(( ERR != 0 )) && { printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to obtain lock on ~/.ssh/agents." >&2; return 1; }
(( ERR != 0 )) && {
printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to obtain lock on ~/.ssh/agents." >&2
return 1
}
else
printf "\\033[1;31;40m%s\\033[0;39m\\n" "File locking unsupported on this platform." >&2
printf "\\033[1;31;40m%s\\033[0;39m\\n" "File locking unsupported on '$PLATFORM'." >&2
return 1
fi
# Read the socket list (bash v3+ compliant)
# Read the socket list (bash v2+ compliant)
while read -u "$FD" -r SOCK; do
[[ -n "$SOCK" ]] && SSH_AUTH_SOCKS+=("$SOCK")
done
ERR=$?
# Close the file descriptor (which on Linux releases the lock too).
# Close the file descriptor (which on Linux releases the flock too).
exec {FD}<&-
# On Darwin, release the lock on the file.
rm -f ~/.ssh/agents.lock
rm -f "$HOME/.ssh/agents.lock"
# Remove the . in the mtime.
SSH_AGENTS_MTIME="${SSH_AGENTS_MTIME/\.}"
# Error out if the data couldn't be read.
(( ERR != 0 )) && { printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to read ssh-agent socket list." >&2; unset SSH_AUTH_SOCKS; return 1; }
(( ERR != 0 )) && {
printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to read ssh-agent socket list." >&2
unset SSH_AUTH_SOCKS SSH_AGENTS_MTIME
return 1
}
return 0
}
__write_ssh_agents() {
# Write all unique ssh agent sockets into the ~/.ssh/agents file.
# Returns: 0 = Processed and wrote the agents file without issue.
# 1 = Error processing/writing the agents file.
# 2 = The SSH_AUTH_SOCKS array may be out of date as the agents file'a mtime has changed.
@ -89,40 +105,43 @@ __write_ssh_agents() {
# Remove any duplicates from SSH_AUTH_SOCKS.
for ((I = 0; I < ${#SSH_AUTH_SOCKS[@]}; I++)); do
[[ -z "${SSH_AUTH_SOCKS[$I]}" ]] && continue
for ((J = 0; J < ${#SOCKS[@]}; J++)); do
[[ "${SSH_AUTH_SOCKS[$I]}" == "${SOCKS[$J]}" ]] && continue 2
done
# Only add the socket if it's still viable.
[[ -n "${SSH_AUTH_SOCKS[$I]}" ]] && {
SSH_AUTH_SOCK="${SSH_AUTH_SOCKS[$I]}" ssh-add -l >/dev/null 2>&1
(( $? < 2 )) && SOCKS+=("${SSH_AUTH_SOCKS[$I]}")
}
(( $? <= 1 )) && SOCKS+=("${SSH_AUTH_SOCKS[$I]}")
done
# Determine the platform being logged into.
PLATFORM="$(uname -s)"
# Lock the ~/.ssh/agents file.
if [[ "$(uname -s)" == "Linux" ]]; then
if [[ "$PLATFORM" == "Linux" ]]; then
# Make sure SSH_AUTH_SOCKS has the most up to date data.
MTIME="$(stat --format=%.9Y ~/.ssh/agents)"
MTIME="$(stat --format=%.9Y "$HOME/.ssh/agents")"
(( ${MTIME/\.} > SSH_AGENTS_MTIME )) && return 2
# Lock the agents file.
{ exec {FD}>~/.ssh/agents && flock -E 10 -e -w 0.5 "$FD"; } || {
if (( $? == 10 )); then
exec {FD}<"$HOME/.ssh/agents" && flock -E 10 -e -w 0.5 "$FD"
ERR=$?
if (( ERR == 10 )); then
printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to obtain lock on ~/.ssh/agents." >&2
else
printf "\\033[1;31;40m%s\\033[0;39m\\n" "Flock usage error" >&2
fi
return 1
}
elif (( ERR > 0 )); then
printf "\\033[1;31;40m%s\\033[0;39m\\n" "Flock usage error." >&2
return 1
fi
elif [[ "$(uname -s)" == "Darwin" ]]; then
# Make sure SSH_AUTH_SOCKS has the most up to date data.
MTIME="$(stat --format=%.9Y ~/.ssh/agents)"
MTIME="$(stat --format=%.9Y "$HOME/.ssh/agents")"
(( ${MTIME/\.} > SSH_AGENTS_MTIME )) && return 2
# Do locking the sucky way on OSX.
for ((I = 0; I < 6; I++)); do
if shlock -p "$$" -f ~/.ssh/agents.lock; then
exec {FD}>~/.ssh/agents
for ((I = 0; I <= 5; I++)); do
if shlock -p "$$" -f "$HOME/.ssh/agents.lock"; then
exec {FD}<"$HOME/.ssh/agents"
ERR=0
break
else
@ -130,38 +149,48 @@ __write_ssh_agents() {
sleep 0.1
fi
done
(( ERR != 0 )) && { printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to obtain lock on ~/.ssh/agents." >&2; return 1; }
(( ERR != 0 )) && {
printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to obtain lock on ~/.ssh/agents." >&2
return 1
}
else
printf "\\033[1;31;40m%s\\033[0;39m\\n" "File locking unsupported on this platform." >&2
printf "\\033[1;31;40m%s\\033[0;39m\\n" "File locking unsupported on '$PLATFORM'." >&2
return 1
fi
# Write the cleaned array to disk.
printf "%s\\n" "${SOCKS[@]}" >~/.ssh/agents 2>/dev/null
ERR=$?
ERR=-1
[[ -n "${SOCKS[*]}" ]] && { printf "%s\\n" "${SOCKS[@]}" >"$HOME/.ssh/agents" 2>/dev/null; ERR=$?; }
# Release locks.
exec {FD}>&-
rm -f ~/.ssh/agents.lock
rm -f "$HOME/.ssh/agents.lock"
# Error out if the data couldn't be written.
(( ERR != 0 )) && { printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to write ssh-agent socket list." >&2; return 1; }
if (( ERR == -1 )); then
rm -f "$HOME/.ssh/agents" 2>/dev/null
elif (( ERR >= 1 )); then
rm -f "$HOME/.ssh/agents" 2>/dev/null
printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to write ssh-agent socket list." >&2
return 1
fi
return 0
}
__ssh_agent_prompt_command() {
# If necessary, find and activate a new ssh agent socket before each prompt is displayed.
# Returns: 0 = All is good.
# 1 = And error occured.
local ERR SSH_AUTH_SOCKS=()
# 1 = An error occured.
local ERR
if [[ -z "$SSH_AUTH_SOCK" ]]; then
ERR=2
else
SSH_AUTH_SOCK="$SSH_AUTH_SOCK" ssh-add -l >/dev/null 2>&1
ssh-add -l >/dev/null 2>&1
ERR=$?
fi
(( ERR == 2 )) && {
# Read previous sockets from ~/.ssh/agents.
# Read alternative sockets from ~/.ssh/agents.
__read_ssh_agents || {
unset SSH_AUTH_SOCK
return 1
@ -173,25 +202,22 @@ __ssh_agent_prompt_command() {
else
# Start a new agent.
eval "$(ssh-agent -s 2>/dev/null | grep -v 'echo'; printf "%s" "ERR=${PIPESTATUS[0]}")"
(( ERR > 0 )) && { printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to start ssh-agent - continuing with no agent." >&2; return 1; }
(( ERR > 0 )) && {
printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to start new ssh-agent - continuing with no agent."
return 1
}
printf "\\033[1;32;40m%s\\033[0;39m\\n" "Started new ssh-agent."
fi
# Update the agents file.
while :; do
__write_ssh_agents
ERR=$?
(( ERR == 2 )) && { __read_ssh_agents || return 1; } && continue
(( ERR == 1 )) && return 1
break
done
}
return 0
}
imagebin() {
[[ -z "$1" ]] && { printf "%s: %s\\n" "Usage" "${FUNCNAME[0]} <filename>" >&2; return 1; }
curl -F file="@${1:-}" https://imagebin.ca/upload.php | grep ^url: | cut -d: -f2-
[[ -z "$1" ]] && {
printf "%s: %s\\n" "Usage" "${FUNCNAME[0]} <filename>" >&2
return 1
}
curl -F file="@$1" https://imagebin.ca/upload.php | grep '^url:' | cut -d: -f2-
}
# Make bash a little more pleasent - these are valid for all versions.
@ -203,17 +229,19 @@ IGNOREEOF=0
# History control.
HISTCONTROL="ignoredups"
HISTFILE="$HOME/.bash_history-${HOSTNAME%%.*}"
HISTFILESIZE=100000
HISTFILESIZE=1000000
HISTIGNORE="bg:bg *:fg:fg *:jobs:exit:clear:history"
HISTSIZE=-1
HISTTIMEFORMAT="%d/%m/%y %H:%M:%S "
history -r
# Determine the colour of the username in the prompt.
if (( $(id -u) == 0 )); then
if [[ "$LOGNAME" == "root" ]]; then
COLOUR=1 # Red
else
elif [[ "$LOGNAME" == "tadgy" ]]; then
COLOUR=2 # Green
else
COLOUR=5 # Purple
fi
# Version specific set up.
@ -221,18 +249,20 @@ if (( BASH_VERSINFO[0] >= 4 )); then
# Add to the shopts.
shopt -s checkjobs dirspell
# Set the prompts.
# Trim the path in the prompt.
PROMPT_DIRTRIM=2
# Coloured username + host + directory:
PS1="[\[$(tput bold)$(tput setaf $COLOUR)\]\u\[$(tput sgr0)\]@\[$(tput bold)$(tput setaf 3)\]\h\[$(tput sgr0)\]] \[$(tput bold)$(tput setaf 4)\]\w\[$(tput sgr0)\] ->"
PS1="[\[$(tput bold)$(tput setaf "$COLOUR")\]\u\[$(tput sgr0)\]@\[$(tput bold)$(tput setaf 3)\]\h\[$(tput sgr0)\]] \[$(tput bold)$(tput setaf 4)\]\w\[$(tput sgr0)\] ->"
else
# Set the prompts.
# Coloured username + host + directory:
PS1="[\[$(tput bold)$(tput setaf $COLOUR)\]\u\[$(tput sgr0)\]@\[$(tput bold)$(tput setaf 3)\]\h\[$(tput sgr0)\]] \[$(tput bold)$(tput setaf 4)\]\$(echo \"\${PWD/#\$HOME/~}\" | awk -F/ '{if (NF>3) {printf \".../\" \$(NF-1) \"/\" \$NF} else {printf \$0}}')\[$(tput sgr0)\] ->"
# shellcheck disable=SC2154
PS1="[\[$(tput bold)$(tput setaf "$COLOUR")\]\u\[$(tput sgr0)\]@\[$(tput bold)$(tput setaf 3)\]\h\[$(tput sgr0)\]] \[$(tput bold)$(tput setaf 4)\]\$(echo \"\${PWD/#\$HOME/~}\" | awk -F/ '{if (NF>3) {printf \".../\" \$(NF-1) \"/\" \$NF} else {printf \$0}}')\[$(tput sgr0)\] ->"
fi
unset COLOUR
# Set the debugger prompt.
# shellcheck disable=SC2155
export PS4="+(\[\e[1;33;40m\]\$?\[$(tput sgr0)\]) \[$(tput bold)$(tput setaf 4)\]\${BASH_SOURCE##*/}\[$(tput sgr0)\]\${FUNCNAME[0]:+(\[$(tput bold)$(tput setaf 2)\]\${FUNCNAME[0]}\[$(tput sgr0)\])}:\[$(tput bold)$(tput setaf 1)\]\$LINENO\[$(tput sgr0)\]: "
# The commands to execute before the prompt is displayed.
@ -241,12 +271,18 @@ PROMPT_COMMAND="__ssh_agent_prompt_command"
# Common aliases.
hash bc >/dev/null 2>&1 && alias bc='bc -lq'
hash diff >/dev/null 2>&1 && alias diff='diff --color=auto -u'
hash grep >/dev/null 2>&1 && alias egrep='grep -E --color=auto'
hash grep >/dev/null 2>&1 && alias fgrep='grep -F --color=auto'
hash grep >/dev/null 2>&1 && alias grep='grep --color=auto'
hash gpg2 >/dev/null 2>&1 && {
alias gpg='command gpg2'
alias gpg2='gpg2 --pinentry-mode=loopback'
}
hash grep >/dev/null 2>&1 && {
alias egrep='grep -E --color=auto'
alias fgrep='grep -F --color=auto'
alias grep='grep --color=auto'
}
hash nc >/dev/null 2>&1 && alias pastebin='nc termbin.com 9999'
hash screen >/dev/null 2>&1 && alias screen='screen -Ua'
hash shellcheck >/dev/null 2>&1 && alias shellcheck='shellcheck -x'
# Auto start the ssh agent and add keys for scp/sftp/ssh.
hash scp ssh ssh-add >/dev/null 2>&1 && alias scp='_EXEC=scp ssh'
hash sftp ssh ssh-add >/dev/null 2>&1 && alias sftp='_EXEC=sftp ssh'
hash ssh ssh-add >/dev/null 2>&1 && ssh() {
@ -255,13 +291,16 @@ hash ssh ssh-add >/dev/null 2>&1 && ssh() {
if [[ -z "$SSH_AUTH_SOCK" ]]; then
ERR=2
else
SSH_AUTH_SOCK="$SSH_AUTH_SOCK" ssh-add -l >/dev/null 2>&1
ssh-add -l >/dev/null 2>&1
ERR=$?
fi
(( ERR == 2 )) && __ssh_agent_prompt_command && ssh-add
(( ERR == 1 )) && ssh-add
if (( ERR == 1 )); then
ssh-add
elif (( ERR == 2 )); then
__ssh_agent_prompt_command
ssh-add
fi
command "${_EXEC:-${FUNCNAME[0]}}" "$@"
unset _EXEC
}
# Determine the platform being logged into.
@ -270,9 +309,24 @@ PLATFORM="$(uname -s)"
# Platform specific set up.
if [[ "$PLATFORM" = "Linux" ]]; then
# Linux specific functions.
psgrep() {
[[ -z "$1" ]] && { printf "%s: %s\\n" "Usage" "${FUNCNAME[0]} <something>" >&2; return 1; }
ps -auwwx | command grep -E --color=always -- "(.*RSS.*|$1)" | grep -F -v "(.*RSS.*|"
hash nano >/dev/null 2>&1 && nano() {
# shellcheck disable=SC2155
local NANO_VER="$(command nano --version | awk '/version/ { print $4 }' | cut -d. -f1)"
if [[ -f "$HOME/.nanorc-$NANO_VER" ]]; then
command nano -f "$HOME/.nanorc-$NANO_VER" "$@"
else
printf "%s: %s\\n" "${FUNCNAME[0]}" "no .nanorc for version '$NANO_VER'" >&2
return 1
fi
}
hash ps grep >/dev/null 2>&1 && psgrep() {
if [[ -n "$1" ]]; then
# shellcheck disable=SC2009
ps -auwwx | grep -E --color=always -- "(.*RSS.*|$1)" | grep -F -v '(.*RSS.*|'
else
printf "%s: %s\\n" "Usage" "${FUNCNAME[0]} <something>" >&2
return 1
fi
}
# Linux specific aliases.
@ -288,6 +342,16 @@ if [[ "$PLATFORM" = "Linux" ]]; then
hash pinfo >/dev/null 2>&1 && alias info='pinfo'
hash ping >/dev/null 2>&1 && alias ping='ping -b'
elif [[ "$PLATFORM" = "Darwin" ]]; then
# Create .nanorc symlink if necessary.
[[ ! -e "$HOME/.nanorc" ]] && {
NANO_VER="$(command nano --version | awk '/version/ { print $4 }' | cut -d. -f1)"
if [[ -f "$HOME/.nanorc-$NANO_VER" ]]; then
( cd "$HOME" && ln -sf ".nanorc-$NANO_VER" .nanorc ) || printf "%s: %s\\n" "${BASH_SOURCE##*/}" "failed to create .nanorc symlink" >&2
else
printf "%s: %s\\n" "${BASH_SOURCE##*/}" "no .nanorc for version '$NANO_VER'" >&2
fi
}
# Darwin specific aliases.
hash df >/dev/null 2>&1 && alias df='df -P'
hash ls >/dev/null 2>&1 && alias ls='ls -bFG'

7
.config/.gitignore vendored
View file

@ -1,4 +1,9 @@
GIMP/
dconf/
QtProject.conf
VirtualBox/
chromium/
evince/
libreoffice/
mimeapps.list
pulse/
xfce4/

View file

@ -1,15 +1,17 @@
# Beware! This file is rewritten by htop when settings are changed in the interface.
# The parser is also very primitive, and not human-friendly.
htop_version=3.2.1
htop_version=3.2.2
config_reader_min_version=3
fields=0 48 17 18 38 39 40 2 46 47 49 1
hide_kernel_threads=1
hide_userland_threads=0
hide_running_in_container=0
shadow_other_users=1
show_thread_names=0
show_program_path=0
highlight_base_name=1
highlight_deleted_exe=1
shadow_distribution_path_prefix=0
highlight_megabytes=1
highlight_threads=1
highlight_changes=0
@ -51,7 +53,7 @@ screen:Main=PID USER PRIORITY NICE M_VIRT M_RESIDENT M_SHARE STATE PERCENT_CPU P
.sort_direction=-1
.tree_sort_direction=1
.all_branches_collapsed=0
screen:I/O=PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE
screen:I/O=PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE EXE
.sort_key=IO_RATE
.tree_sort_key=PID
.tree_view=0

4
.gitignore vendored
View file

@ -20,13 +20,13 @@
.lynx.cookies
.mozilla/
.nanorc
.pki/
.rnd
.screen-*/
.sqlite_history
.thumbnails/
.vmware
.vnc
.wget-hsts
.xca
.xinitrc
.xsession
.xsession-errors*

2
.local/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
bin/
lib/

6
.local/share/.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
Trash/
clipit/
gvfs-metadata/
mime/
recently-used.xbel
rss2email.json

View file

@ -193,7 +193,7 @@ GOTOBUFFER:FALSE
#
# In the following line, include the actual full local path to JUMPFILE,
# but do not include 'file://localhost' in the line.
#JUMPFILE:/root/.lynx.jumpfile.html:j
#JUMPFILE:/home/tadgy/.lynx.jumpfile.html:j
.ex
#JUMPFILE:/Lynx_Dir/ips.html:i:IP or Interest group (? for list):
@ -305,7 +305,7 @@ AUTO_SESSION:FALSE
# Users can still customize SESSION_FILE and AUTO_SESSION via
# their .lynxrc file.
#
SESSION_FILE:/root/.lynx.session
SESSION_FILE:/home/tadgy/.lynx.session
.h2 SESSION_LIMIT
# SESSION_LIMIT defines maximum number of: searched strings, goto URLs,
@ -1407,7 +1407,7 @@ PERSISTENT_COOKIES:TRUE
# USE_PERSISTENT_COOKIES and the PERSISTENT_COOKIES option is enabled.
# The cookie file can also be specified in .lynxrc or on the command line.
#
COOKIE_FILE:/root/.lynx.cookies
COOKIE_FILE:/home/tadgy/.lynx.cookies
.h2 COOKIE_SAVE_FILE
# COOKIE_SAVE_FILE is the default file in which persistent cookies are
@ -1576,7 +1576,7 @@ COOKIE_FILE:/root/.lynx.cookies
# (see below), via the 'o'ptions menu, and can save those definitions
# in the .lynxrc file.
#
DEFAULT_BOOKMARK_FILE:/root/.lynx-bookmarks.html
DEFAULT_BOOKMARK_FILE:/home/tadgy/.lynx-bookmarks.html
.h2 MULTI_BOOKMARK_SUPPORT
# If MULTI_BOOKMARK_SUPPORT is set TRUE, and BLOCK_MULTI_BOOKMARKS (see

130
.nanorc-6 Normal file
View file

@ -0,0 +1,130 @@
## Sample initialization file for GNU nano.
##
## Please note that you must have configured nano with --enable-nanorc
## for this file to be read! Also note that this file should not be in
## DOS or Mac format, and that characters specially interpreted by the
## shell should not be escaped here.
##
## To make sure an option is disabled, use "unset <option>".
##
## Quotes inside string parameters don't have to be escaped with
## backslashes. The last double quote in the string will be treated as
## its end. For example, for the "brackets" option, ""')>]}" will match
## ", ', ), >, ], and }.
## When soft line wrapping is enabled, make it wrap lines at blank characters.
set atblanks
## Use auto-indentation.
set autoindent
## When saving a file, create a backup file by adding a tilde (~).
# set backup
## Automatically hard-wrap the current line when it becomes overlong.
# set breaklonglines
## Do case-sensitive searches by default.
# set casesensitive
## Do not use the line below the title bar.
# set emptyline
## Set the line length for wrapping text and justifying paragraphs.
set fill -2
## Draw a vertical stripe at the given column
set guidestripe 161
## Remember the used search/replace strings for the next session.
set historylog
## Display a "scrollbar" on the righthand side of the edit window.
# set indicator
## Scroll the buffer contents per half-screen instead of per line.
# set jumpyscrolling
## Display line numbers to the left of the text area.
set linenumbers
## Enable vim-style lock-files.
set locking
## Use libmagic for syntax highlighting suggestions.
set magic
## Don't display the helpful shortcut lists at the bottom of the screen.
set nohelp
## Don't add newlines to the ends of files.
# set nonewlines
# Save the cursor position of files between editing sessions.
# set positionlog
## Do quick statusbar blanking.
set quickblank
## Do extended regular expression searches by default.
# set regexp
## Make the Home key smarter.
set smarthome
## Enable soft line wrapping (AKA full-line display).
# set softwrap
## Use this spelling checker instead of the internal one.
unset speller
## Show flags in the title bar.
set stateflags
## When justifying text, trailing whitespace will automatically be removed.
set trimblanks
## The two characters used to indicate the presence of tabs and spaces.
set whitespace »·
## Detect word boundaries more accurately by treating punctuation
## characters as parts of words.
set wordbounds
## Let an unmodified Backspace or Delete erase the marked region, without
## affecting the cut-buffer.
# set zap
## Paint the interface elements of nano.
set errorcolor brightwhite,red
set functioncolor magenta
set keycolor brightwhite
set numbercolor brightwhite,magenta
set promptcolor brightwhite,magenta
set selectedcolor brightwhite,blue
set statuscolor brightwhite,magenta
set stripecolor ,magenta
set titlecolor brightwhite,magenta
## Include all existing syntax highlight definitions.
include "/usr/share/nano/*.nanorc"
## Key bindings.
## The following five functions are not bound to any key by default.
## You may wish to choose different keys than the ones suggested here.
# bind ^S savefile main
# bind M-Q findprevious main
# bind M-W findnext main
# bind M-B cutwordleft main
# bind M-N cutwordright main
## Set this if your Backspace key sends Del most of the time.
# bind Del backspace all
# Unbind the ^J (justification) shortcut as it's annoying.
unbind ^J main
# Allow ^Z to suspend nano.
bind ^Z suspend main
# Allow marking using ^Space.
bind ^Space mark main

View file

@ -7,9 +7,6 @@
##
## To make sure an option is disabled, use "unset <option>".
##
## For the options that take parameters, the default value is given.
## Other options are unset by default.
##
## Quotes inside string parameters don't have to be escaped with
## backslashes. The last double quote in the string will be treated as
## its end. For example, for the "brackets" option, ""')>]}" will match
@ -19,7 +16,10 @@
set atblanks
## Use auto-indentation.
# set autoindent
set autoindent
## When saving a file, create a backup file by adding a tilde (~).
# set backup
## Automatically hard-wrap the current line when it becomes overlong.
# set breaklonglines
@ -34,7 +34,7 @@ set atblanks
set fill -2
## Draw a vertical stripe at the given column
set guidestripe 160
set guidestripe 161
## Remember the used search/replace strings for the next session.
set historylog
@ -51,12 +51,18 @@ set linenumbers
## Enable vim-style lock-files.
set locking
## Use libmagic for syntax highlighting suggestions.
set magic
## Don't display the helpful shortcut lists at the bottom of the screen.
set nohelp
## Don't add newlines to the ends of files.
# set nonewlines
# Save the cursor position of files between editing sessions.
# set positionlog
## Do quick statusbar blanking.
set quickblank
@ -72,6 +78,9 @@ set smarthome
## Use this spelling checker instead of the internal one.
set speller "aspell -x -c"
## Show flags in the title bar.
set stateflags
## When justifying text, trailing whitespace will automatically be removed.
set trimblanks
@ -80,20 +89,14 @@ set whitespace »·
## Detect word boundaries more accurately by treating punctuation
## characters as parts of words.
# set wordbounds
set wordbounds
## Let an unmodified Backspace or Delete erase the marked region, without affecting the cut-buffer.
## Let an unmodified Backspace or Delete erase the marked region, without
## affecting the cut-buffer.
# set zap
# Show flags in the title bar.
set stateflags
# Use libmagic for syntax highlighting suggestions.
set magic
## Paint the interface elements of nano.
## This is an example; by default there are no colors.
set errorcolor brightwhite,red
set functioncolor magenta
set keycolor brightwhite
@ -119,12 +122,9 @@ include "/usr/share/nano/*.nanorc"
# bind M-N cutwordright main
## Set this if your Backspace key sends Del most of the time.
# bind Del backspace all
# Unbind the ^J (justification) shortcut as it's annoying.
unbind ^J main
# Allow ^Z to suspend nano.
bind ^Z suspend main
# Allow marking using ^Space.
bind ^Space mark main

View file

@ -34,11 +34,16 @@ Host as.hosts.slackware.network esx0.hosts.slackware.network esx1.hosts.slackwar
Host afterdark.org.uk
Port 6722
Host lil phil tommy-wifi
Host chuckie lil phil tommy-wifi
ForwardX11Trusted yes
Host nas0 nas1 nas backupnas
ForwardAgent no
ClearAllForwardings yes
Host esx0 esx1 esx2 esx3 gw vcsa
User root
PubKeyAuthentication no
ForwardAgent no
ClearAllForwardings yes
@ -47,12 +52,20 @@ Host rpi0 rpi1 rpi2
ForwardAgent no
ClearAllForwardings yes
Host build-* clone-* full-*
Host build-*
User root
# GitHub.
Host clone-* full-*
User root
ClearAllForwardings yes
# Git services.
Host github.com
User git
IdentityFile ${HOME}/.ssh/id_ed25519_github
ForwardAgent no
ClearAllForwardings yes
Host git.rlworkman.net
ForwardAgent no
ClearAllForwardings yes