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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
# ANSI color scheme script by pfh
# 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 ""
awk 'BEGIN{

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
# Author: SuNjACk
# 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.
# 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
# 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; }
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;')"

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
# ANSI Color -- use these variables to easily have different color
# 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
# The Bash Prompt HOWTO: 6.1. Colours

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
# Author: machinebacon
# 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/
# http://frexx.de/xterm-256-notes/data/colortable16.sh

View file

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

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
# ANSI color scheme script by pfh
# 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
# 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
# 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
# Author: pfh

View file

@ -1,23 +1,22 @@
#!/usr/bin/env bash
#!/bin/bash
# Author: GekkoP
# Source: http://linuxbbq.org/bbs/viewtopic.php?f=4&t=1656#p33189
f=3 b=4
for j in f b; do
for i in {0..7}; do
printf -v $j$i %b "\e[${!j}${i}m"
done
for i in {0..7}; do
printf -v $j$i %b "\e[${!j}${i}m"
done
done
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
d=$'\e[1m'
t=$'\e[0m'
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

View file

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

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
# Author: crshd
# 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
# Source: http://crunchbang.org/forums/viewtopic.php?pid=151601#p151601
@ -29,4 +29,4 @@ cat << EOF
$f3 ██████████████████████████████████████████
$f3 ██████████████████████████████████████
$rst
EOF
EOF

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
# ANSI color scheme script by pfh
# 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

View file

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