commit 74187b99da074c517d28c3ac26d3f232cbc6e546
parent fa3fec81dcad4e816f21c64721e49095531e9ef9
Author: Matthew Carlson <matt@mcarlson.xyz>
Date: Tue, 17 Aug 2021 17:19:59 -0400
scripting
Diffstat:
10 files changed, 168 insertions(+), 20 deletions(-)
diff --git a/.config/vim/vimrc b/.config/vim/vimrc
@@ -183,3 +183,8 @@ noremap <S-Down> :resize -1<CR>
" remove highlight from searched text
nnoremap <CR> :noh<CR><CR>
+
+" basic compiler
+map <leader>c :w! \| !compile.sh <c-r>%<CR>
+map <leader>o :!compile.sh -o <c-r>%<CR><CR>
+map <leader>x :!compile.sh -c %<CR>
diff --git a/.config/x/xresources b/.config/x/xresources
@@ -140,3 +140,18 @@ st.rows : 24
st.mousefg : 7
st.mousebg : 0
st.defaultattr : 11
+
+! xmenu
+xmenu.borderWidth : 3
+xmenu.separatorWidth : 5
+xmenu.height : 25
+xmenu.width : 300
+xmenu.gap : 0
+xmenu.background : col0
+xmenu.foreground : col7
+xmenu.selbackground : col2
+xmenu.selforeground : col0
+xmenu.separator : col7
+xmenu.border : col2
+xmenu.font : monospace:size=16,Font Awesome 5 Pro Solid:size=16
+xmenu.alignment : LeftAlignment
diff --git a/.local/bin/bar/bat.sh b/.local/bin/bar/bat.sh
@@ -12,10 +12,7 @@ BAT_HALF_ICON=''
BAT_THREE_QUARTERS_ICON=''
BAT_FULL_ICON=''
-get_energy_left() {
- energy_left="$(printf '%.2f' "$(printf '%s\n' "scale=4; ${POWER_SUPPLY_ENERGY_FULL}/${POWER_SUPPLY_ENERGY_FULL_DESIGN} * 100" | bc)")"
- env HERBE_ID=/0 herbe "Energy left: ${energy_left}%"
-}
+get_energy_left() { energy_left="$(printf '%.2f' "$(printf '%s\n' "scale=4; ${POWER_SUPPLY_ENERGY_FULL}/${POWER_SUPPLY_ENERGY_FULL_DESIGN} * 100" | bc)")" ; }
bar() {
# prefix could be charging, warning, or both
@@ -48,7 +45,9 @@ main() {
# bar usage
case ${BLOCK_BUTTON} in
- 1) get_energy_left ;;
+ 1) get_energy_left
+ env HERBE_ID=/0 herbe "Energy left: ${energy_left}%"
+ ;;
esac
}
diff --git a/.local/bin/bar/cpu.sh b/.local/bin/bar/cpu.sh
@@ -32,7 +32,7 @@ calculate_usage() {
}
# top ten intensive processes
-get_procs() { ps -eo comm,%cpu | sort -k 2 -n -r | head | tail | sed 's/$/%/' ; }
+get_procs() { procs="$(ps -eo comm,%cpu | sort -k 2 -n -r | head | tail | sed 's/$/%/')" ; }
get_usage() { [ -f "${USAGE}" ] && usage=$(cat "${USAGE}") ; }
@@ -61,7 +61,9 @@ main() {
# bar usage
case ${BLOCK_BUTTON} in
- 1) env HERBE_ID=/1 herbe "$(get_procs)" ;;
+ 1) get_procs
+ herbe "${procs}"
+ ;;
esac
}
diff --git a/.local/bin/bar/date.sh b/.local/bin/bar/date.sh
@@ -11,7 +11,7 @@ main() {
[ ${#} -eq 0 ] && bar
# bar usage
- case ${BLOCK_BUTTON} in 1) env HERBE_ID=/1 herbe "$(cal)" ;; esac
+ case ${BLOCK_BUTTON} in 1) herbe "$(cal)" ;; esac
}
main "${@}"
diff --git a/.local/bin/bar/net.sh b/.local/bin/bar/net.sh
@@ -22,6 +22,19 @@ get_interface() {
interface="${interface##*/}"
}
+get_local_ip() { local_ip="$(ip a | grep -i "\<${1}\>" | awk '{ for (i = 1; i <= NF; i++) { if ($i ~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\/[0-9]*/) { print $i } } }')" ; }
+
+get_ip_addresses() {
+ get_interface 'wifi' && get_local_ip "${interface}"
+ local_wifi_ip="${local_ip:-N/A}"
+
+ get_interface 'eth' && get_local_ip "${interface}"
+ local_eth_ip="${local_ip:-N/A}"
+
+ public_ip="$(curl ifconfig.me/ip)"
+ public_ip="${public_ip:-N/A}"
+}
+
get_wifi() {
get_interface 'wifi'
@@ -78,7 +91,12 @@ main() {
[ ${#} -eq 0 ] && bar
# bar usage
- case ${BLOCK_BUTTON} in 1) open ;; esac
+ case ${BLOCK_BUTTON} in
+ 1) open ;;
+ 3) get_ip_addresses
+ herbe "$(printf '%s\n%s\n%s' "Wifi IP: ${local_wifi_ip}" "Eth IP: ${local_eth_ip}" "Public IP: ${public_ip}")"
+ ;;
+ esac
while getopts 'o' opt; do
case "${opt}" in
diff --git a/.local/bin/bar/vol.sh b/.local/bin/bar/vol.sh
@@ -15,7 +15,7 @@ get_scontrol() {
fi
}
-get_vol() { amixer get "${scontrol}" -M | grep '\[[0-9][0-9]*\%\]' | awk '{ print $5 }' | head -n 1 | tr -d '[:punct:]' ; }
+get_vol() { vol=$(amixer get "${scontrol}" -M | grep '\[[0-9][0-9]*\%\]' | awk '{ print $5 }' | head -n 1 | tr -d '[:punct:]') ; }
toggle() {
[ "${scontrol}" = 'Master' ] && amixer set "${scontrol}" toggle
@@ -25,12 +25,12 @@ toggle() {
# set volume linearly
set_vol() {
amixer set "${scontrol}" "${2}"%"${1}" -M
- vol=$(get_vol)
+ get_vol
env HERBE_ID=/0 herbe "Volume: ${vol}%" &
}
bar() {
- vol=$(get_vol)
+ get_vol
# check if muted
if [ "${scontrol}" = 'Master' ] || [ "${scontrol}" = 'PCM' ]; then
diff --git a/.local/bin/compile.sh b/.local/bin/compile.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+#
+# compile
+
+. "${HOME:-/home/${USER}/}/.local/bin/symlink.sh"
+
+main() {
+ # use POSIX-compliant way to follow symlink
+ file="$(follow_link "${1}")"
+
+ # dir, base, ext are good things to know
+ dir="${file%/*}/"
+ base="${file%.*}"
+ ext="${file##*.}"
+
+ # dir does not exist and exist
+ cd "${dir}" || return 1
+
+ # clear screen for neatness
+ clear
+
+ # add some functionality to this basic compiler
+ while getopts 'c:o:' opt; do
+ case "${opt}" in
+ # shell check if called with c flag and shell script
+ c) [ "${OPTARG##*.}" = 'sh' ] && shellcheck -x "${OPTARG}"
+ return
+ ;;
+ # open same file name with different extension if called with o flag
+ o) case "${OPTARG##*.}" in
+ 'tex') [ -f "${OPTARG%.*}.pdf" ] && "${HOME:-/home/${USER}/}/.local/bin/open.sh" "${OPTARG%.*}.pdf" >/dev/null 2>&1 & ;;
+ esac
+ return
+ ;;
+ *) break ;;
+ esac
+ done
+
+ # different compile options based on file extension
+ case "${ext}" in
+ # GNU compilers
+ 'c') cc "${file}" -o "${base}" && "${base}" ;;
+ 'cpp') g++ "${file}" -o "${base}" && "${base}" ;;
+ 'java') javac "${file}" && java "${file}" ;;
+ 'py') python "${file}" ;;
+ 'sh') sh "${file}" ;;
+ 'tex') printf 'reached'
+ if grep -iq 'addbibresource' "${file}"; then
+ biber --input-directory "${dir}" "${base}"
+ fi
+ pdflatex --output-directory="${dir}" "${base}"
+ # remove annoying files generated by latex
+ for f in "${base}".*; do
+ case "${f##*.}" in
+ 'aux' | \
+ 'bbl' | \
+ 'bcf' | \
+ 'blg' | \
+ 'lof' | \
+ 'log' | \
+ 'out' | \
+ 'toc' | \
+ 'xml') rm -f "${f}" ;;
+ esac
+ done
+ ;;
+ esac
+}
+
+main "${@}"
diff --git a/.local/bin/menu.sh b/.local/bin/menu.sh
@@ -4,16 +4,16 @@
main() {
xmenu << EOF | sh &
-Applications
- IMG:./icons/web.png Web Browser ${BROWSER}
- IMG:./icons/gimp.png Image editor gimp
+ Programs
+ Web Browser ${BROWSER}
+ Image editor gimp-2.99
+ Text Editor ${TERMINAL} -c ${TERMINAL} -e ${EDITOR}
-Terminal (xterm) xterm
-Terminal (urxvt) urxvt
-Terminal (st) st
+ Terminal ${TERMINAL}
-Shutdown poweroff
-Reboot reboot
+ Lock lock.sh
+ Shutdown doas shutdown -h now
+ Restart doas shutdown -r now
EOF
}
diff --git a/.local/bin/symlink.sh b/.local/bin/symlink.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+#
+# symlink
+
+follow_link() {
+ # no file provided
+ [ "${1:-}" ] || return 1
+
+ file="${1}"
+
+ [ -e "${file%/}" ] || file=${file%"${file##*[!/]}"}
+ [ -d "${file:-/}" ] && file="${file}/"
+
+ while :; do
+ if [ ! "${file}" = "${file%/*}" ]; then
+ # follow with cd
+ case "${file}" in
+ /*) cd -P "${file%/*}/" 2>/dev/null || break ;;
+ *) cd -P "./${file%/*}" 2>/dev/null || break ;;
+ esac
+ file=${file##*/}
+ fi
+
+ # if not link print the actual file
+ if [ ! -L "${file}" ]; then
+ file="${PWD%/}${file:+/}${file}"
+ printf '%s\n' "${file:-/}"
+ break
+ fi
+
+ # use ls -dl to follow link
+ link="$(ls -dl -- "${file}" 2>/dev/null)" || break
+ file="${link#*" ${file} -> "}"
+ done
+}
+
+main() { follow_link "${@}" ; }
+
+main "${@}"