Compare commits

..

9 Commits

10 changed files with 95 additions and 286 deletions

View File

@ -22,7 +22,7 @@ alias la='ls -laFh --color=auto'
alias grep='grep --color=auto' alias grep='grep --color=auto'
# Change layout of lsblk to include FSTYPE and remove MAJ:MIN, RM, and RO collumns. # Change layout of lsblk to include FSTYPE and remove MAJ:MIN, RM, and RO collumns.
alias lsblk='lsblk -o NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT' alias lsblk='lsblk -o NAME,FSTYPE,SIZE,TYPE,MOUNTPOINTS'
# Always use sudo when using nmap. # Always use sudo when using nmap.
alias nmap='sudo -E nmap' alias nmap='sudo -E nmap'
@ -38,3 +38,6 @@ alias countupdates='checkupdates | tee >(wc -l)'
# Grep through updates listed by checkudpdates # Grep through updates listed by checkudpdates
alias grepupdates='checkupdates | grep' alias grepupdates='checkupdates | grep'
# Start mpv in fullscreen and paused
alias mpv='mpv --fs --pause'

11
.bashrc.d/aping.bash Normal file
View File

@ -0,0 +1,11 @@
aping() { # aping: beep when ping fails (reverse behavior of `ping -a <address>`)
local address="$1"
while true; do
if ping -c 1 $address; then
:
else
printf "\a"
fi
sleep 1
done
}

View File

@ -1,20 +0,0 @@
cn-fwupd() {
local addr="$1"
local puf="$2"
local ext="${puf##*.}"
case $ext in
zip)
printf 'put %q firmware/update.zip' "$puf" | cnsftp $addr
cnssh $addr pushupdate FULL
;;
puf)
printf 'put %q firmware/' "$puf" | cnsftp $addr
cnssh $addr puf
;;
*)
echo "Error: Bad file type. Currently, only'.zip' and '.puf' file types are supported."
;;
esac
}

View File

@ -1,46 +0,0 @@
cn-progload() {
local addr="$1"
local project="$2" # /foo/bar/baz.bunk
local ext="${project##*.}" # bunk
local projfname="${project%.*}" # /foo/bar/baz
local projfnamebase="${projfname##*/}" # baz
local zigstash
zigstash="$(mktemp /tmp/$projfnamebase.XXXX.zig)"
# Add a zero in front of the 3rd arg
local slot="0${3}"
# expand only to the last 2 digits of $slot
slot="${slot: -2}"
case $ext in
vtz)
if [[ -n $slot ]]; then
echo "==NOTICE== Ignoring slot number for touchpanel project..."
fi
printf 'put %q %q' "$project" "/display/"| cnsftp "$addr"
cnssh "$addr" projectload
;;
lpz)
if [[ -z $slot ]]; then
echo "==NOTICE== No target program slot defined. Assuming Slot 01..."
slot=01
fi
# Stop and delete current program in $slot
cnssh "$addr" killprog -P$slot
# Upload
printf 'put %q %q' "$project" "/Program$slot" | cnsftp "$addr"
# Load the program
cnssh "$addr" progload -p:$slot
# Zip up the sig file in a temporary location
zip -j - "$projfname.sig" > "$zigstash"
# Upload the zig
printf 'put %q %q' "$zigstash" "/Program$slot/$projfnamebase.zig" | cnsftp "$addr"
;;
*)
echo "Error: Bad file type. Currently only supports vtz and lpz projects."
;;
esac
}

View File

@ -1,63 +0,0 @@
cn-scp() {
shopt -q extglob; local extglob_set=$?
if ((extglob_set)); then
echo "cn-scp: extglob must be set for this function to work properly."
return 1
fi
local source="$1"
local dest="$2"
local sep=":"
local host sourcefile destfile
if [[ -z $source ]]; then
echo "Error: No source provided"
return 1
elif [[ -z $dest ]]; then
echo "Error: No destination provided"
return 1
fi
# Host determination:
local loopcount=0
for i in "$source" "$dest"; do
case "$i" in
# Will match if $sep exists in string once
*@("$sep")* )
# Check if $host is unset
if [[ -z $host ]]; then
host="${i%%:*}"
sourcefile="${source#*:}"
destfile="${dest#*:}"
# If this is the first run of the loop, the remote is the source
if [[ "$loopcount" == 0 ]]; then
operation="get"
# If this is the second run of the loop, the remote is the dest
elif [[ "$loopcount" == 1 ]]; then
operation="put"
# If this is anything other than the first or second loop, GTFO
else
echo "Error: Loop counting error."
return 1
fi
continue
else
echo "Error: Remote path for *both* source and destination is not supported."
return 1
fi
;;
*)
((loopcount++))
continue
;;
esac
((loopcount++))
done
# END: Host determination
printf '%q %q %q' "$operation" "$sourcefile" "$destfile" | cnsftp "$host"
}

View File

@ -1,154 +0,0 @@
cnssh() { # Helper for sshing into Crestron devices
#
# USAGE
#
# cnssh <ip address> [command]
#
#
# OPTIONS
#
# -u <username> Specify the username to use with ssh
# Default: "Crestron"
#
# CONFIG ARRAY: cnssh_conf
#
#
# | Option | Valid Args | Default | Description |
# | ------------- | ------------- | ------------- | --------------------------------------------- |
# | uname | <string> | "Crestron" | The username for use with ssh |
# | pass | <string> | "" | The password for use with ssh (via sshpass) |
# | addr | <string> | <ip address> | The address of the remote device |
# | cmd | <string> | [command] | The command to execute on the remote device |
####
# Config init
# Initialize runtime config array
declare -A conf
# Initialize config array if it doesn't already exist
if [[ ! -v cnssh_conf[@] ]]; then
declare -A cnssh_conf
else
for opt in "${!cnssh_conf[@]}"; do
conf[$opt]=${cnssh_conf[$opt]}
done
fi
# Initialize and populate default config array
declare -A dconf
dconf=(
[method]="ssh"
[uname]="Crestron"
[pass]=""
)
# Apply defaults to running config
for opt in "${!dconf[@]}"; do
# Don't apply the default if it's already set
if [[ ! -v conf[$opt] ]]; then
conf[$opt]=${dconf[$opt]}
fi
done
declare -A sshopts
sshopts=(
[StrictHostKeyChecking]="no"
[GlobalKnownHostsFile]="/dev/null"
[UserKnownHostsFile]="/dev/null"
[LogLevel]="ERROR"
)
# Config init
####
####
# Option Parsing
while getopts ":u:" opt; do
case $opt in
u)
conf[uname]="$OPTARG"
;;
\?)
echo "Unknown option -$OPTARG"
return 1
;;
:)
echo "Option requires argument: -$OPTARG"
return 1
;;
esac
done
# Remove parsed options from $@
shift $((OPTIND -1))
# Set the address based on the first
# arg if not already set in config array
if [[ ! -v conf[addr] ]]; then
conf[addr]="$1"
shift 1
fi
# Set the command as the rest of argv
# if not already set in config array
if [[ ! -v conf[cmd] ]]; then
conf[cmd]="$*"
fi
# Set ssh user name
sshopts[User]="${conf[uname]}"
# Set ssh host if not using sftp mode
case ${conf[method]} in
ssh)
:
;;
sftp)
unset "conf[cmd]"
;;
*)
echo "Unknown method: ${conf[method]}"
;;
esac
# Option Parsing
####
####
# Main
sshpass -p "${conf[pass]}" \
"${conf[method]}" \
$( # Format sshopts as a string that an ssh program understands
for opt in "${!sshopts[@]}"; do
printf '%s %s=%s ' "-o" "$opt" "${sshopts[$opt]}"
done
) \
"${conf[addr]}" \
"${conf[cmd]}"
# Main
####
}
cnsftp() {
# Initialize config array if it doesn't already exist
if [[ ! -v cnssh_conf[@] ]]; then
declare -A cnssh_conf
fi
# Set sftp mode instead of ssh
cnssh_conf[method]="sftp"
cnssh_conf[addr]="$*"
cnssh
unset "cnssh_conf[method]"
unset "cnssh_conf[addr]"
}

3
.bashrc.d/mkcdtemp.bash Normal file
View File

@ -0,0 +1,3 @@
mkcdtemp() {
cd "$(mktemp -d)" || return
}

27
.bashrc.d/newfiles.bash Normal file
View File

@ -0,0 +1,27 @@
newfiles() {
# Path to watch. If the first parameter isn't set, just use /dev/
local path="${1:-/dev/}"
# Seconds without new events before exiting inotifywait
local timeout=10
printf "New files in %s:\n\n" "$path"
inotifywait \
--monitor \
--event create \
--timeout $timeout \
--format '%w%f' \
--quiet \
"$path"
local return=$?
if [[ $return == 2 ]]; then
printf "\nNo new events in %s seconds. Exiting.\n\n" $timeout
return 0
else
printf "\nE: inotifywait returned %s. Exiting.\n\n" $return
return $return
fi
}

48
.bashrc.d/phsp.bash Normal file
View File

@ -0,0 +1,48 @@
phsp() {
local input="$*"
local char
local out
# Iterate over each character in the string
for i in $(seq 0 ${#input}); do
# Get the current character using parameter expansion
char=${input:$i:1}
# Match against alphabet (using uppercase of variable)
case ${char^^} in
A) out="Alfa" ;;
B) out="Bravo" ;;
C) out="Charlie" ;;
D) out="Delta" ;;
E) out="Echo" ;;
F) out="Foxtrot" ;;
G) out="Golf" ;;
H) out="Hotel" ;;
I) out="India" ;;
J) out="Juliett" ;;
K) out="Kilo" ;;
L) out="Lima" ;;
M) out="Mike" ;;
N) out="November" ;;
O) out="Oscar" ;;
P) out="Papa" ;;
Q) out="Quebec" ;;
R) out="Romeo" ;;
S) out="Sierra" ;;
T) out="Tango" ;;
U) out="Uniform" ;;
V) out="Victor" ;;
W) out="Whiskey" ;;
X) out="X-ray" ;;
Y) out="Yankee" ;;
Z) out="Zulu" ;;
[[:space:]]) out="" ;;
*) out=""
esac
if [ "$out" ]; then
printf "%s: %s\n" "$char" "$out"
else
printf "\n"
fi
done
}

View File

@ -1,4 +1,4 @@
# If you don't have weechat installed, connect to the existing tmux session through mosh # If you don't have weechat installed, connect to the existing tmux session through mosh
[[ ! -s /usr/bin/weechat ]] && alias weechat='mosh vps -- tmux attach -dt weechat' [[ ! -s /usr/bin/weechat ]] && alias weechat='mosh thurstyserv -- tmux -L tl-weemux attach -dt tl-weemux'
# If you are thurstylark-vps, connect to the existing tmux session locally # If you are thurstylark-vps, connect to the existing tmux session locally
[[ "$HOSTNAME" = "thurstylark-vps" ]] && alias weechat='tmux attach -dt weechat' [[ "$HOSTNAME" = "thurstyserv" ]] && alias weechat='tmux -L tl-weemux attach -dt tl-weemux'