summaryrefslogtreecommitdiff
path: root/scripts/cli
diff options
context:
space:
mode:
authorSuleyman Farajli <suleyman@farajli.net>2025-11-25 18:47:27 +0400
committerSuleyman Farajli <suleyman@farajli.net>2025-11-25 18:47:27 +0400
commitd947956270b092df10637bb3531441caca698b86 (patch)
tree8c32170ef044687b11be79398140a36430e2ff0a /scripts/cli
parentc388ade6b6d955138698731af02dfbe5c676439a (diff)
feat: new api for scripts
Diffstat (limited to 'scripts/cli')
-rwxr-xr-xscripts/cli/noc15
-rwxr-xr-xscripts/cli/nospac11
-rwxr-xr-xscripts/cli/sdev80
-rwxr-xr-xscripts/cli/slight27
-rwxr-xr-xscripts/cli/svol30
5 files changed, 37 insertions, 126 deletions
diff --git a/scripts/cli/noc b/scripts/cli/noc
index 575566c..63bee86 100755
--- a/scripts/cli/noc
+++ b/scripts/cli/noc
@@ -1,6 +1,19 @@
#!/bin/sh
-# Remove empty lines and all the comments starting with "#"
+. "lib_common.sh"
+
+help() {
+cat << EOF
+${0}: Remove empty lines and all the comments starting with '#'.
+options:
+ -h Print this message and exit
+EOF
+exit 0
+}
+
+[ "${1}" = "-h" ] && help
+
+[ ${#} -gt 0 ] && invalid_use
for file in "${@}"; do
sed -i "s/\s*#.*//g; /^$/ d" "${file}"
diff --git a/scripts/cli/nospac b/scripts/cli/nospac
index 6ba466a..7ee5b36 100755
--- a/scripts/cli/nospac
+++ b/scripts/cli/nospac
@@ -1,5 +1,7 @@
#!/bin/sh
+. "lib_common.sh"
+
help() {
cat << EOF
${0}: Replace all the spaces in file and directory
@@ -7,13 +9,12 @@ names with "_" in in the current directory.
options:
-h Print this message and exit
EOF
+exit 0
}
-if [ ${#} -gt 0 ]; then
- [ ${#} = 1 ] && [ "${1}" = "-h" ] && help && exit 0
- printf "%s: Invalid usage\nTry '%s -h' for help.\n" "${0}" "${0}"
- exit 1
-fi
+[ "${1}" = "-h" ] && help
+
+[ ${#} -gt 0 ] && invalid_use
for file in ./*; do
newfile=$(echo "${file}" | tr ' ' '_')
diff --git a/scripts/cli/sdev b/scripts/cli/sdev
deleted file mode 100755
index c227771..0000000
--- a/scripts/cli/sdev
+++ /dev/null
@@ -1,80 +0,0 @@
-#!/bin/sh
-
-. slib
-
-help() {
-cat << EOF
-${0}: Disable and Enable devices
-options:
- -e [dev] Enable dev
- -d [dev] Disable dev
- -t [dev] Toggle dev
- -l List devices
- -h Print this message and exit
-
-Note: Nondescriptive inputs may disable/enable unwanted devices.
-EOF
-
-exit 0
-}
-
-get_id() {
- if ! dev=$(xinput list --name-only | grep -i -m1 "${1}" ); then
- err "Couldn't get device"
- fi
- id="${dev#∼ }"
-}
-
-xenable() {
- echo "${id}"
-
- if ! xinput enable "${1}" > /dev/null 2>&1; then
- err "Failed to enable dev."
- else
- exit 0
- fi
-}
-
-xdisable() {
- echo "${id}"
-
- if ! xinput disable "${1}" > /dev/null 2>&1; then
- err "Failed to disable dev."
- else
- exit 0
- fi
-}
-
-check_program "xinput"
-
-while getopts "e:d:t:lh" option; do
- case "${option}" in
- e)
- get_id "${OPTARG}"
- xenable "${id}"
- ;;
- d)
- get_id "${OPTARG}"
- xdisable "${id}"
- ;;
- t)
- get_id "${OPTARG}"
-
- [ "${id}" = "${dev}" ] && xdisable "${id}"
- xenable "${id}"
- ;;
- l)
- if ! xinput list 2>/dev/null; then
- err "Listing Failed"
- else
- exit 0
- fi
- ;;
- h) help ;;
-
- *) invalid_use -h ;;
-
- esac
-done
-
-invalid_use
diff --git a/scripts/cli/slight b/scripts/cli/slight
index 54edbcd..4efbf19 100755
--- a/scripts/cli/slight
+++ b/scripts/cli/slight
@@ -1,6 +1,7 @@
#!/bin/sh
-. slib
+. "lib_common.sh"
+. "lib_handle.sh"
help() {
cat << EOF
@@ -14,34 +15,22 @@ options:
NOTE: Script interprets values as percentages
EOF
-
exit 0
}
-check_program "brightnessctl"
-
+brightness_handle check_program
[ ${#} != 1 ] && [ ${#} != 2 ] && invalid_use
while getopts "i:d:s:ph" option; do
case "${option}" in
- i) run --reload-status "brightnessctl set +${OPTARG}%" ;;
-
- d) run --reload-status "brightnessctl set ${OPTARG}-%" ;;
-
- s) run --reload-status "brightnessctl set ${OPTARG}%" ;;
-
- p)
- if ! echo $(( ($(brightnessctl g) * 100) / $(brightnessctl m) )); then
- err "Failed to get current brightness"
- else
- exit 0
- fi
- ;;
+ i) run --reload-status "brightness_handle up ${OPTARG}" ;;
+ d) run --reload-status "brightness_handle down ${OPTARG}" ;;
+ s) run --reload-status "brightness_handle set ${OPTARG}" ;;
+ t) run --reload-status "brightness_handle toggle" ;;
+ p) brightness_handle get-current ;;
h) help ;;
*) invalid_use -h ;;
-
esac
done
-
invalid_use
diff --git a/scripts/cli/svol b/scripts/cli/svol
index 0488633..5ce6848 100755
--- a/scripts/cli/svol
+++ b/scripts/cli/svol
@@ -1,10 +1,11 @@
#!/bin/sh
-. slib
+. "lib_common.sh"
+. "lib_handle.sh"
help() {
cat << EOF
-${0}: Wrapper script to change volume
+${0}: Change volume
options:
-i [Vol] Increase volume by Vol
-d [Vol] Decrease volume by Vol
@@ -13,37 +14,24 @@ options:
-t Toggle between mute and unmute
-h Print this message and exit
EOF
-
exit 0
}
-check_program "pactl" "pulseaudio must be installed"
+volume_handle check_program
[ $# != 1 ] && [ $# != 2 ] && invalid_use
while getopts "i:d:s:pth" option; do
case "${option}" in
- i) run --reload-status "pactl set-sink-volume @DEFAULT_SINK@ +${OPTARG}%" ;;
-
- d) run --reload-status "pactl set-sink-volume @DEFAULT_SINK@ -${OPTARG}%" ;;
-
- s) run --reload-status "pactl set-sink-volume @DEFAULT_SINK@ ${OPTARG}%" ;;
-
- t) run --reload-status "pactl set-sink-mute @DEFAULT_SINK@ toggle" ;;
-
- p)
- if ! pactl get-sink-volume @DEFAULT_SINK@ \
- | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' | head -n1 2>/dev/null; then
- err "Failed to get current volume"
- else
- exit 0
- fi
- ;;
+ i) run --reload-status "volume_handle up ${OPTARG}" ;;
+ d) run --reload-status "volume_handle down ${OPTARG}" ;;
+ s) run --reload-status "volume_handle set ${OPTARG}" ;;
+ t) run --reload-status "volume_handle toggle" ;;
+ p) volume_handle get-current ;;
h) help ;;
*) invalid_use -h ;;
esac
done
-
invalid_use