summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2020-05-15 11:57:45 -0400
committerAdam T. Carpenter <atc@53hor.net>2020-05-15 11:57:45 -0400
commit6e14535ef56fd91b05eb170f71f7989d7435d8c3 (patch)
tree9d9e947cd11af17cffa37000f635f682070ed5af
parent2930e933305e653f2f26deacd459dd100f257168 (diff)
downloadscripts-6e14535ef56fd91b05eb170f71f7989d7435d8c3.tar.xz
scripts-6e14535ef56fd91b05eb170f71f7989d7435d8c3.zip
added dmenu port handling script, changed thresholds in cpuload
-rwxr-xr-xabraham-porter.sh155
-rwxr-xr-xi3blocks-cpuload.sh4
-rw-r--r--i3blocks-message.sh34
3 files changed, 191 insertions, 2 deletions
diff --git a/abraham-porter.sh b/abraham-porter.sh
new file mode 100755
index 0000000..1498ccf
--- /dev/null
+++ b/abraham-porter.sh
@@ -0,0 +1,155 @@
+#!/bin/sh
+
+## Configuration
+dmenu="rofi -dmenu"
+doas="doas"
+terminal="alacritty"
+printer="rofi -width -81 -e"
+ports_dir="/usr/local/poudriere/ports/default"
+pkglist="$HOME/.pkglist"
+poudriere_jail="121x64"
+
+
+## Error codes
+OK=0
+NO_ACTION_PROVIDED=3
+NO_PORT_PROVIDED=4
+NO_PKG_DESCR_FOUND=5
+NO_WANT_TERM_PROVIDED=6
+
+
+## Gets a port name from the user with dmenu
+get_port() {
+ cwd=$(pwd)
+ cd "$ports_dir"
+ printf "%s\n" */* | $dmenu -p "Choose a port"
+ cd "$cwd"
+}
+
+
+## Prompt user if they want to run command in a new term
+wants_term() {
+ choice=$($dmenu -p "Do you want to do this in a new terminal?" << EOF
+no
+yes
+EOF
+ )
+ [ $action = "yes" ] && return 1
+ [ $action = "no" ] && return 0
+ exit $NO_WANT_TERM_PROVIDED
+}
+
+
+## Gets an action from the user with dmenu
+get_action() {
+ action=$($dmenu -p "Whadyagonnado" << EOF
+1. print pkg-descr
+2. set options
+3. set options, add to pkglist
+4. set options, build pkg
+5. set options, build pkg, add to pkglist
+6. add to pkglist
+7. set options on pkglist
+8. build entire pkglist (lengthy and intensive!)
+EOF
+ )
+ echo "$action" | cut -d'.' -f1
+}
+
+
+## Handle printing a package description file
+handle_print_pkg_desc() {
+ port=$(get_port)
+ [ -z $port ] && exit $NO_PORT_PROVIDED
+ pkg_descr="$ports_dir"/$port/pkg-descr
+ [ ! -f "$pkg_descr" ] && exit $NO_PKG_DESCR_FOUND
+ text=$(cat "$ports_dir"/$port/pkg-descr)
+ $printer "$text"
+}
+
+
+## Handle appending a port to the pkglist. Skips appending if already present
+handle_append_pkglist() {
+ port="$1"
+ grep -q $port "$pkglist" && exit $OK
+ cp "$pkglist" "$pkglist".bak
+ echo $port >> "$pkglist"
+ sort "$pkglist" -o "$pkglist"
+ echo $port
+}
+
+
+## Handle running poudriere options on a single port
+handle_poudriere_options_single() {
+ port="$1"
+ $terminal -e $doas poudriere options -c $port
+ echo $port
+}
+
+
+## Handle running poudriere bulk on a single port
+handle_poudriere_bulk_single() {
+ port="$1"
+ if wants_term; then
+ $terminal -e $doas poudriere bulk -j "$jail" $port
+ else
+ $doas poudriere bulk -j "$jail" $port
+ fi
+}
+
+
+## Handle running poudriere options on pkglist
+handle_poudriere_options_pkglist() {
+ $terminal -e $doas poudriere options -f "$pkglist"
+}
+
+
+## Handle running poudriere bulk on pkglist
+handle_poudriere_bulk_pkglist() {
+ if wants_term; then
+ $terminal -e $doas poudriere bulk -j "$jail" -f "$pkglist"
+ else
+ $doas poudriere bulk -j "$jail" -f "$pkglist"
+ fi
+}
+
+
+## Main
+action=$(get_action)
+case $action in
+ 1)
+ # 1. print pkg-descr
+ handle_print_pkg_desc
+ ;;
+ 2)
+ # 2. set options
+ handle_poudriere_options_single $(get_port)
+ ;;
+ 3)
+ # 3. set options, add to pkglist
+ handle_poudriere_options_single $(handle_append_pkglist $(get_port))
+ ;;
+ 4)
+ # 4. set options, build pkg
+ handle_poudriere_bulk_single $(handle_poudriere_options_single $(get_port))
+ ;;
+ 5)
+ # 5. set options, build pkg, add to pkglist
+ handle_poudriere_bulk_single $(handle_poudriere_options_single $(handle_append_pkglist $(get_port)))
+ ;;
+ 6)
+ # 6. add to pkglist
+ handle_append_pkglist $(get_port)
+ ;;
+ 7)
+ # 7. set options on pkglist
+ handle_poudriere_options_pkglist
+ ;;
+ 8)
+ # 8. build entire pkglist (lengthy and intensive!)
+ handle_poudriere_bulk_pkglist
+ ;;
+ *)
+ exit $NO_ACTION_PROVIDED
+ ;;
+esac
diff --git a/i3blocks-cpuload.sh b/i3blocks-cpuload.sh
index dd30311..65ccaca 100755
--- a/i3blocks-cpuload.sh
+++ b/i3blocks-cpuload.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-low=25
-high=75
+low=50
+high=90
icon_low=󰒲
icon_mid=󰜎
icon_high=󱅝
diff --git a/i3blocks-message.sh b/i3blocks-message.sh
new file mode 100644
index 0000000..8f7c5e2
--- /dev/null
+++ b/i3blocks-message.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+ticker_length=5 # words
+
+# Echo the text the ticker should scroll over. No newlines!
+init_ticker() {
+ echo $(fortune | tr -d '\b\r\\' | tr -s '\n\t\v\f' ' ' | tr -s '"' "'")
+}
+
+# Cut up text for ticker tape.
+gen_ticker() {
+ echo $(
+ echo $text | cut -d' ' -f$word_index-$((
+ $word_index + $ticker_length - 1
+ ))
+ )
+}
+
+while true; do
+ # If ticker text is empty, re-initialize text and word index. Then generate
+ # ticker text.
+ [ -z "$ticker_text" ] && word_index=1 && text=$(init_ticker)
+ ticker_text=$(gen_ticker) && ((word_index += 1))
+
+ # Print i3status header string.
+ printf ",[{"
+
+ # Print ticker tape JSON.
+ printer "$ticker_text" "left" 250
+
+ # Print the rest of the status string.
+ echo "${line#,\[}"
+ #printf "%s" $line
+
+done