♻️ refactor(bin): use /bin/bash instead of any other alias

This commit is contained in:
Sergio Laín 2024-05-26 20:08:18 +02:00
parent 95ae0e344d
commit 736a5d6740
No known key found for this signature in database
GPG key ID: FB00AF7015FFE76B
27 changed files with 182 additions and 183 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
function printHelp() { function printHelp() {
cat <<EOF cat <<EOF
@ -23,193 +23,193 @@ EOF
} }
function debugPrint() { function debugPrint() {
if [ "$DEBUG" -eq 1 ]; then if [ "$DEBUG" -eq 1 ]; then
echo "[DEBUG] $1" echo "[DEBUG] $1"
fi fi
} }
function toggleFreeze() { function toggleFreeze() {
# Skip this function if --dry-run flag was provided # Skip this function if --dry-run flag was provided
if [[ $DRYRUN == "1" ]]; then return 0; fi if [[ $DRYRUN == "1" ]]; then return 0; fi
# Get pids of process tree # Get pids of process tree
PIDS=$(pstree -p "$PID" | grep -oP '\(\K[^\)]+') PIDS=$(pstree -p "$PID" | grep -oP '\(\K[^\)]+')
debugPrint "PIDs: $PIDS" debugPrint "PIDs: $PIDS"
# Prevent suspending itself # Prevent suspending itself
local pid_of_script=$$ local pid_of_script=$$
if echo "$PIDS" | grep -q "$pid_of_script"; then if echo "$PIDS" | grep -q "$pid_of_script"; then
echo "You are trying to suspend the hyprfreeze process." echo "You are trying to suspend the hyprfreeze process."
exit 1 exit 1
fi fi
# Suspend or resume processes # Suspend or resume processes
if [[ "$(ps -o state= "$PID")" == T ]]; then if [[ "$(ps -o state= "$PID")" == T ]]; then
debugPrint "Resuming processes..." debugPrint "Resuming processes..."
kill -CONT $PIDS 2>/dev/null && echo "Resumed $(ps -p "$PID" -o comm= 2>/dev/null) (PID $PID)" || exit 1 kill -CONT $PIDS 2>/dev/null && echo "Resumed $(ps -p "$PID" -o comm= 2>/dev/null) (PID $PID)" || exit 1
else else
debugPrint "Suspending processes..." debugPrint "Suspending processes..."
kill -STOP $PIDS 2>/dev/null && echo "Suspended $(ps -p "$PID" -o comm= 2>/dev/null) (PID $PID)" || exit 1 kill -STOP $PIDS 2>/dev/null && echo "Suspended $(ps -p "$PID" -o comm= 2>/dev/null) (PID $PID)" || exit 1
fi fi
} }
function getPidByActive() { function getPidByActive() {
debugPrint "Getting PID by active window..." debugPrint "Getting PID by active window..."
PID=$(hyprctl activewindow -j | jq '.pid') PID=$(hyprctl activewindow -j | jq '.pid')
debugPrint "PID by active window: $PID" debugPrint "PID by active window: $PID"
} }
function getPidByPid() { function getPidByPid() {
debugPrint "Getting PID by PID: $1" debugPrint "Getting PID by PID: $1"
# Check if process pid exists # Check if process pid exists
if ! ps -p "$1" &>/dev/null; then if ! ps -p "$1" &>/dev/null; then
echo "Process ID $1 not found" echo "Process ID $1 not found"
exit 1 exit 1
fi fi
PID=$1 PID=$1
} }
function getPidByName() { function getPidByName() {
debugPrint "Getting PID by name: $1" debugPrint "Getting PID by name: $1"
# Check if process name exists # Check if process name exists
if ! pidof -x "$1" >/dev/null; then if ! pidof -x "$1" >/dev/null; then
echo "Process name $1 not found" echo "Process name $1 not found"
exit 1 exit 1
fi fi
# Get last process if there are multiple # Get last process if there are multiple
PID=$(pidof "$1" | awk '{print $NF}') PID=$(pidof "$1" | awk '{print $NF}')
debugPrint "PID by name: $PID" debugPrint "PID by name: $PID"
} }
function getPidByProp() { function getPidByProp() {
debugPrint "Getting PID by prop..." debugPrint "Getting PID by prop..."
if ! command -v hyprprop; then if ! command -v hyprprop; then
echo "You need to install 'hyprprop' to use this feature. (https://github.com/vilari-mickopf/hyprprop)" echo "You need to install 'hyprprop' to use this feature. (https://github.com/vilari-mickopf/hyprprop)"
exit 1 exit 1
fi fi
PID=$(hyprprop | jq '.pid') PID=$(hyprprop | jq '.pid')
debugPrint "PID by prop: $PID" debugPrint "PID by prop: $PID"
} }
function printInfo() { function printInfo() {
debugPrint "Printing process info...\n" debugPrint "Printing process info...\n"
echo -e "$(tput bold)Process tree:$(tput sgr0)" echo -e "$(tput bold)Process tree:$(tput sgr0)"
ps -p "$PID" 2>/dev/null && pstree -p "$PID" ps -p "$PID" 2>/dev/null && pstree -p "$PID"
echo -e "\n$(tput bold)Process threads:$(tput sgr0)" echo -e "\n$(tput bold)Process threads:$(tput sgr0)"
ps -eLo pid,tid,comm | grep "$PID" 2>/dev/null ps -eLo pid,tid,comm | grep "$PID" 2>/dev/null
echo -e "\n$(tput bold)Process ID$(tput sgr0) = $PID \ echo -e "\n$(tput bold)Process ID$(tput sgr0) = $PID \
\n$(tput bold)Process name$(tput sgr0) = $(ps -p "$PID" -o comm= 2>/dev/null) \ \n$(tput bold)Process name$(tput sgr0) = $(ps -p "$PID" -o comm= 2>/dev/null) \
\n$(tput bold)Process state$(tput sgr0) = $(ps -o state= -p "$PID" 2>/dev/null)\n" \n$(tput bold)Process state$(tput sgr0) = $(ps -o state= -p "$PID" 2>/dev/null)\n"
} }
function sendNotification() { function sendNotification() {
debugPrint "Sending notification..." debugPrint "Sending notification..."
local title local title
title=$( [[ "$(ps -p "$PID" -o state=)" == T ]] && title=$([[ "$(ps -p "$PID" -o state=)" == T ]] &&
echo "Suspended $(ps -p "$PID" -o comm= 2>/dev/null)" || echo "Suspended $(ps -p "$PID" -o comm= 2>/dev/null)" ||
echo "Resumed $(ps -p "$PID" -o comm= 2>/dev/null)") echo "Resumed $(ps -p "$PID" -o comm= 2>/dev/null)")
local message="PID $PID" local message="PID $PID"
notify-send "${title}" "${message}" -t "$NOTIF_TIMEOUT" -a Hyprfreeze notify-send "${title}" "${message}" -t "$NOTIF_TIMEOUT" -a Hyprfreeze
} }
function args() { function args() {
# Track required flags # Track required flags
local required_flag_count=0 local required_flag_count=0
# Parse options # Parse options
local options="hap:n:rst:" local options="hap:n:rst:"
local long_options="help,active,pid:,name:,prop,silent,notif-timeout:,info,dry-run,debug" local long_options="help,active,pid:,name:,prop,silent,notif-timeout:,info,dry-run,debug"
local parsed_args local parsed_args
parsed_args=$(getopt -o "$options" --long "$long_options" -n "$(basename "$0")" -- "$@") parsed_args=$(getopt -o "$options" --long "$long_options" -n "$(basename "$0")" -- "$@")
eval set -- "$parsed_args" eval set -- "$parsed_args"
while true; do while true; do
case $1 in case $1 in
-h | --help) -h | --help)
printHelp printHelp
exit 0 exit 0
;; ;;
-a | --active) -a | --active)
((required_flag_count++)) ((required_flag_count++))
FLAG_ACTIVE=true FLAG_ACTIVE=true
;; ;;
-p | --pid) -p | --pid)
((required_flag_count++)) ((required_flag_count++))
shift shift
FLAG_PID="$1" FLAG_PID="$1"
;; ;;
-n | --name) -n | --name)
((required_flag_count++)) ((required_flag_count++))
shift shift
NAME_FLAG="$1" NAME_FLAG="$1"
;; ;;
-r | --prop) -r | --prop)
((required_flag_count++)) ((required_flag_count++))
FLAG_PROP=true FLAG_PROP=true
;; ;;
-s | --silent) -s | --silent)
SILENT=1 SILENT=1
;; ;;
-t | --notif-timeout) -t | --notif-timeout)
shift shift
NOTIF_TIMEOUT="$1" NOTIF_TIMEOUT="$1"
;; ;;
--info) --info)
INFO=1 INFO=1
;; ;;
--dry-run) --dry-run)
DRYRUN=1 DRYRUN=1
;; ;;
--debug) --debug)
DEBUG=1 DEBUG=1
;; ;;
--) --)
shift # Skip -- argument shift # Skip -- argument
break break
;; ;;
*) *)
exit 1 exit 1
;; ;;
esac esac
shift shift
done done
# Check if more than one required flag is provided, or if none was provided # Check if more than one required flag is provided, or if none was provided
if [ $required_flag_count -ne 1 ]; then if [ $required_flag_count -ne 1 ]; then
printHelp printHelp
exit 1 exit 1
fi fi
} }
function main() { function main() {
debugPrint "Starting main function..." debugPrint "Starting main function..."
# Get pid by a required flag # Get pid by a required flag
if [ "$FLAG_ACTIVE" = true ]; then if [ "$FLAG_ACTIVE" = true ]; then
getPidByActive getPidByActive
elif [ -n "$FLAG_PID" ]; then elif [ -n "$FLAG_PID" ]; then
getPidByPid "$FLAG_PID" getPidByPid "$FLAG_PID"
elif [ -n "$NAME_FLAG" ]; then elif [ -n "$NAME_FLAG" ]; then
getPidByName "$NAME_FLAG" getPidByName "$NAME_FLAG"
elif [ "$FLAG_PROP" = true ]; then elif [ "$FLAG_PROP" = true ]; then
getPidByProp getPidByProp
fi fi
# Suspend or resume process # Suspend or resume process
toggleFreeze toggleFreeze
# Run these functions after PID is obtained # Run these functions after PID is obtained
if [ $INFO -eq 1 ]; then printInfo; fi if [ $INFO -eq 1 ]; then printInfo; fi
if [ $SILENT -ne 1 ]; then sendNotification; fi if [ $SILENT -ne 1 ]; then sendNotification; fi
debugPrint "End of main function." debugPrint "End of main function."
} }
SILENT=0 SILENT=0

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
set -e set -e

View file

@ -1,4 +1,4 @@
#!/usr/bin/bash #!/bin/bash
# Script created by: https://github.com/moguay # Script created by: https://github.com/moguay

View file

@ -1,3 +1,3 @@
#!/usr/bin/bash #!/bin/bash
--smart-case --smart-case

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# ANSI color scheme script by pfh # ANSI color scheme script by pfh
# Source: http://crunchbang.org/forums/viewtopic.php?pid=139126#p139126 # Source: http://crunchbang.org/forums/viewtopic.php?pid=139126#p139126

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
echo "This should be a smooth gradient" echo "This should be a smooth gradient"
echo "" echo ""
awk 'BEGIN{ awk 'BEGIN{

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# Author: SuNjACk # Author: SuNjACk
# Source: http://crunchbang.org/forums/viewtopic.php?pid=135226#p135226 # Source: http://crunchbang.org/forums/viewtopic.php?pid=135226#p135226

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# Tom Hale, 2016. MIT Licence. # Tom Hale, 2016. MIT Licence.
# Print out 256 colours, with each number printed in its corresponding colour # Print out 256 colours, with each number printed in its corresponding colour

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# Author: HostGrady # Author: HostGrady
# Font used: https://patorjk.com/software/taag/#p=display&f=Cricket&t=suckless # Font used: https://patorjk.com/software/taag/#p=display&f=Cricket&t=suckless

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
pcs() { for i in {0..7}; do echo -en "\e[${1}$((30+$i))m \u2588\u2588 \e[0m"; done; } pcs() { for i in {0..7}; do echo -en "\e[${1}$((30+$i))m \u2588\u2588 \e[0m"; done; }
pcsbright() { for i in {0..7}; do echo -en "\e[${1}$((90+$i))m \u2588\u2588 \e[0m"; done; } pcsbright() { for i in {0..7}; do echo -en "\e[${1}$((90+$i))m \u2588\u2588 \e[0m"; done; }
printf "\n%s\n%s\n\n" "$(pcs)" "$(pcsbright '1;')" printf "\n%s\n%s\n\n" "$(pcs)" "$(pcsbright '1;')"

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# ANSI Color -- use these variables to easily have different color # ANSI Color -- use these variables to easily have different color
# and format output. Make sure to output the reset sequence after # and format output. Make sure to output the reset sequence after

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# Daniel Crisman's ANSI color chart script from # Daniel Crisman's ANSI color chart script from
# The Bash Prompt HOWTO: 6.1. Colours # The Bash Prompt HOWTO: 6.1. Colours

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# Author: machinebacon # Author: machinebacon
# Source: http://linuxbbq.org/bbs/viewtopic.php?f=4&t=1656#p33237 # Source: http://linuxbbq.org/bbs/viewtopic.php?f=4&t=1656#p33237

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# Original: http://frexx.de/xterm-256-notes/ # Original: http://frexx.de/xterm-256-notes/
# http://frexx.de/xterm-256-notes/data/colortable16.sh # http://frexx.de/xterm-256-notes/data/colortable16.sh

View file

@ -1,8 +1,8 @@
#!/usr/bin/env bash #!/bin/bash
# Author: venam # Author: venam
cat << EOF cat <<EOF
                         
                                                                 

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# ANSI color scheme script by pfh # ANSI color scheme script by pfh
# Source: http://crunchbang.org/forums/viewtopic.php?pid=144011#p144011 # Source: http://crunchbang.org/forums/viewtopic.php?pid=144011#p144011

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# ANSI color scheme script by pfh # ANSI color scheme script by pfh
# Source: http://crunchbang.org/forums/viewtopic.php?pid=157979#p157979 # Source: http://crunchbang.org/forums/viewtopic.php?pid=157979#p157979

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# ANSI color scheme script by pfh # ANSI color scheme script by pfh
# Source: http://crunchbang.org/forums/viewtopic.php?pid=151602#p151602 # Source: http://crunchbang.org/forums/viewtopic.php?pid=151602#p151602

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# ANSI color scheme script featuring PACMAN # ANSI color scheme script featuring PACMAN
# Author: pfh # Author: pfh

View file

@ -1,23 +1,22 @@
#!/usr/bin/env bash #!/bin/bash
# Author: GekkoP # Author: GekkoP
# Source: http://linuxbbq.org/bbs/viewtopic.php?f=4&t=1656#p33189 # Source: http://linuxbbq.org/bbs/viewtopic.php?f=4&t=1656#p33189
f=3 b=4 f=3 b=4
for j in f b; do for j in f b; do
for i in {0..7}; do for i in {0..7}; do
printf -v $j$i %b "\e[${!j}${i}m" printf -v $j$i %b "\e[${!j}${i}m"
done done
done done
for i in {0..7}; do for i in {0..7}; do
printf -v fbright$i %b "\e[9${i}m" printf -v fbright$i %b "\e[9${i}m"
done done
d=$'\e[1m' d=$'\e[1m'
t=$'\e[0m' t=$'\e[0m'
v=$'\e[7m' v=$'\e[7m'
cat <<EOF
cat << EOF
$f1███$d$fbright$fbright1▄$t $f2███$d$fbright$fbright2▄$t $f3███$d$fbright3▄$t $f4███$d$fbright4▄$t $f5███$d$fbright5▄$t $f6███$d$fbright6▄$t $f7███$d$fbright7▄$t $f1███$d$fbright$fbright1▄$t $f2███$d$fbright$fbright2▄$t $f3███$d$fbright3▄$t $f4███$d$fbright4▄$t $f5███$d$fbright5▄$t $f6███$d$fbright6▄$t $f7███$d$fbright7▄$t
$f1███$d$fbright$fbright1█$t $f2███$d$fbright$fbright2█$t $f3███$d$fbright3█$t $f4███$d$fbright4█$t $f5███$d$fbright5█$t $f6███$d$fbright6█$t $f7███$d$fbright7█$t $f1███$d$fbright$fbright1█$t $f2███$d$fbright$fbright2█$t $f3███$d$fbright3█$t $f4███$d$fbright4█$t $f5███$d$fbright5█$t $f6███$d$fbright6█$t $f7███$d$fbright7█$t

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# ANSI color scheme script by pfh # ANSI color scheme script by pfh
# Source: http://crunchbang.org/forums/viewtopic.php?pid=143700#p143700 # Source: http://crunchbang.org/forums/viewtopic.php?pid=143700#p143700
@ -6,18 +6,18 @@
f=3 b=4 f=3 b=4
for j in f b; do for j in f b; do
for i in {0..7}; do for i in {0..7}; do
printf -v $j$i %b "\e[${!j}${i}m" printf -v $j$i %b "\e[${!j}${i}m"
done done
done done
for i in {0..7}; do for i in {0..7}; do
printf -v fbright$i %b "\e[9${i}m" printf -v fbright$i %b "\e[9${i}m"
done done
bld=$'\e[1m' bld=$'\e[1m'
rst=$'\e[0m' rst=$'\e[0m'
inv=$'\e[7m' inv=$'\e[7m'
cat << EOF cat <<EOF
$f3 ▄ $f1 ▄▄ $f2 ▄▄ $f4 ▄▄ $f5 ▄▄ $f6 ▄▄ $f3 ▄ $f1 ▄▄ $f2 ▄▄ $f4 ▄▄ $f5 ▄▄ $f6 ▄▄
$f3 ███▄▄ $f1 ██▬██▬██ $f2 ██▬██▬██ $f4 ██▬██▬██ $f5 ██▬██▬██ $f6 ██▬██▬██ $f3 ███▄▄ $f1 ██▬██▬██ $f2 ██▬██▬██ $f4 ██▬██▬██ $f5 ██▬██▬██ $f6 ██▬██▬██

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# ANSI color scheme script featuring Space Invaders # ANSI color scheme script featuring Space Invaders

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# Author: crshd # Author: crshd
# Source: http://crunchbang.org/forums/viewtopic.php?pid=128584#p128584 # Source: http://crunchbang.org/forums/viewtopic.php?pid=128584#p128584

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# ANSI color scheme script by pfh # ANSI color scheme script by pfh
# Source: http://crunchbang.org/forums/viewtopic.php?pid=151601#p151601 # Source: http://crunchbang.org/forums/viewtopic.php?pid=151601#p151601
@ -29,4 +29,4 @@ cat << EOF
$f3 ██████████████████████████████████████████ $f3 ██████████████████████████████████████████
$f3 ██████████████████████████████████████ $f3 ██████████████████████████████████████
$rst $rst
EOF EOF

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# ANSI color scheme script by pfh # ANSI color scheme script by pfh
# Source: http://crunchbang.org/forums/viewtopic.php?pid=141044#p141044 # Source: http://crunchbang.org/forums/viewtopic.php?pid=141044#p141044

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# Simple CLI for shell-color-scripts # Simple CLI for shell-color-scripts

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
# pipes.sh: Animated pipes terminal screensaver. # pipes.sh: Animated pipes terminal screensaver.
# https://github.com/pipeseroni/pipes.sh # https://github.com/pipeseroni/pipes.sh
# #