From 5c82197471f7bf6a3e69ae32377bdb53ecc7fd07 Mon Sep 17 00:00:00 2001 From: thek4n Date: Sat, 2 Nov 2024 11:14:41 +0300 Subject: [PATCH] make scripts posix sh --- home/user/.local/bin/beep_bigben.sh | 2 +- home/user/.local/bin/beep_imperial_march.sh | 2 +- home/user/.local/bin/beep_nyancat.sh | 2 +- home/user/.local/bin/bluetooth | 4 ++-- home/user/.local/bin/i3_switch_workspace.sh | 2 +- home/user/.local/bin/i3status_wrapper | 13 ++++++------- home/user/.local/bin/killer | 4 ++-- home/user/.local/bin/power_rofi.sh | 4 ++-- home/user/.local/bin/slm | 1 - home/user/.local/bin/slm_rofi.sh | 2 +- home/user/.local/bin/tmux_attach_session.sh | 4 ++-- home/user/.local/bin/tmux_kill_sessions.sh | 4 ++-- home/user/.local/bin/tmux_list_sessions.sh | 5 +---- home/user/.local/bin/tmux_start_session.sh | 2 +- home/user/.local/bin/wifi | 6 +++--- 15 files changed, 26 insertions(+), 31 deletions(-) diff --git a/home/user/.local/bin/beep_bigben.sh b/home/user/.local/bin/beep_bigben.sh index 4a32df6..aa8baba 100755 --- a/home/user/.local/bin/beep_bigben.sh +++ b/home/user/.local/bin/beep_bigben.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh # g# e f# b | b f# g# e | g# f# e b diff --git a/home/user/.local/bin/beep_imperial_march.sh b/home/user/.local/bin/beep_imperial_march.sh index d32c387..ef5039e 100755 --- a/home/user/.local/bin/beep_imperial_march.sh +++ b/home/user/.local/bin/beep_imperial_march.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh # usermod -aG input $USER diff --git a/home/user/.local/bin/beep_nyancat.sh b/home/user/.local/bin/beep_nyancat.sh index 8ad941d..493d923 100755 --- a/home/user/.local/bin/beep_nyancat.sh +++ b/home/user/.local/bin/beep_nyancat.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh beep \ -f 1198.64491 -l 200 \ diff --git a/home/user/.local/bin/bluetooth b/home/user/.local/bin/bluetooth index b1ecda7..d56adec 100755 --- a/home/user/.local/bin/bluetooth +++ b/home/user/.local/bin/bluetooth @@ -5,7 +5,7 @@ bssid="$(bluetoothctl devices | rofi -dmenu -p "Devices: " -l 20 | cut -d' ' -f2 exit_counter=0 until bluetoothctl connect "$bssid" do - ((exit_counter+=1)) + exit_counter=$((exit_counter+1)) if [ "$exit_counter" -gt 3 ]; then break @@ -13,4 +13,4 @@ do echo ... sleep 1 fi -done +done \ No newline at end of file diff --git a/home/user/.local/bin/i3_switch_workspace.sh b/home/user/.local/bin/i3_switch_workspace.sh index 3827f10..8eeae96 100755 --- a/home/user/.local/bin/i3_switch_workspace.sh +++ b/home/user/.local/bin/i3_switch_workspace.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh gen_workspaces() { diff --git a/home/user/.local/bin/i3status_wrapper b/home/user/.local/bin/i3status_wrapper index 24c6b4d..bad77cb 100755 --- a/home/user/.local/bin/i3status_wrapper +++ b/home/user/.local/bin/i3status_wrapper @@ -1,10 +1,10 @@ -#!/usr/bin/env bash +#!/bin/sh # The idea is to define "holder" modules in i3status config and then replace them # In order to make this example work you need to add # order += "tztime holder__headphones" -# and +# and # tztime holder__headphones { # format = "holder__headphones" # } @@ -12,15 +12,14 @@ [ -x "/usr/bin/jq" ] || exec i3status update_holder() { - local instance="$1" - local replacement="$2" + instance="$1" + replacement="$2" echo "$3" | jq --argjson arg_j "$replacement" "(.[] | (select(.instance==\"$instance\"))) |= \$arg_j" } get_device_battery_status() { for uuid in $(timeout 1 bluetoothctl devices | cut -f2 -d' ' 2>/dev/null) do - local device_info device_info="$(timeout 1 bluetoothctl info "$uuid")" if echo "$device_info" | grep -q 'Connected: yes\|Battery Percentage'; then @@ -31,7 +30,7 @@ get_device_battery_status() { } update_json_with_text() { - local json="{ \"full_text\": \"$1\", \"color\": \"#FFFFFF\"}" + json="{ \"full_text\": \"$1\", \"color\": \"#FFFFFF\"}" update_holder "holder__headphones" "$json" "$2" } @@ -48,4 +47,4 @@ i3status | ( json_array="$(echo "$line" | sed -e 's/^,//')" echo "$(update_json_with_text "$(get_device_battery_status)" "$json_array")," done -) +) \ No newline at end of file diff --git a/home/user/.local/bin/killer b/home/user/.local/bin/killer index ca9b1fe..d186993 100755 --- a/home/user/.local/bin/killer +++ b/home/user/.local/bin/killer @@ -1,4 +1,4 @@ #!/bin/sh -pidd="$(ps -u $USER -o pid,%mem,%cpu,comm | sort -b -k2 -r | sed -n '1!p' | rofi -dmenu -i -l 15 | awk '{print $1}')" -kill -15 "$pidd" +pidd="$(ps -u "${USER}" -o pid,%mem,%cpu,comm | sort -b -k2 -r | sed -n '1!p' | rofi -dmenu -i -l 15 | awk '{print $1}')" +kill -15 "$pidd" \ No newline at end of file diff --git a/home/user/.local/bin/power_rofi.sh b/home/user/.local/bin/power_rofi.sh index a4f2102..c24f46c 100755 --- a/home/user/.local/bin/power_rofi.sh +++ b/home/user/.local/bin/power_rofi.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh eval "$(echo "i3-msg exit @@ -6,4 +6,4 @@ reboot shutdown -h now systemctl suspend i3lock -enf -c 1e1e1e -convert canvas:none PNG:- | feh -YF -" | rofi -dmenu -m -1 -i -p "Power")" +convert canvas:none PNG:- | feh -YF -" | rofi -dmenu -m -1 -i -p "Power")" \ No newline at end of file diff --git a/home/user/.local/bin/slm b/home/user/.local/bin/slm index f8ba187..5996d24 100755 --- a/home/user/.local/bin/slm +++ b/home/user/.local/bin/slm @@ -63,4 +63,3 @@ case "$1" in *) shift; cmd_help "$@" ;; esac exit 0 - diff --git a/home/user/.local/bin/slm_rofi.sh b/home/user/.local/bin/slm_rofi.sh index 2849f9e..2c2fdaa 100755 --- a/home/user/.local/bin/slm_rofi.sh +++ b/home/user/.local/bin/slm_rofi.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh choosed_screen_layout="$(slm ls | rofi -dmenu -m -1 -i -p "Select screen layout")" slm load "$choosed_screen_layout" \ No newline at end of file diff --git a/home/user/.local/bin/tmux_attach_session.sh b/home/user/.local/bin/tmux_attach_session.sh index be1bbb8..93a4e53 100755 --- a/home/user/.local/bin/tmux_attach_session.sh +++ b/home/user/.local/bin/tmux_attach_session.sh @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh -readonly tmux_list_sessions_script="$HOME/.local/bin/tmux_list_sessions.sh" +readonly tmux_list_sessions_script="${HOME}/.local/bin/tmux_list_sessions.sh" export FZF_DEFAULT_OPTS="\ ${FZF_DEFAULT_OPTS} diff --git a/home/user/.local/bin/tmux_kill_sessions.sh b/home/user/.local/bin/tmux_kill_sessions.sh index f229233..577c4f4 100755 --- a/home/user/.local/bin/tmux_kill_sessions.sh +++ b/home/user/.local/bin/tmux_kill_sessions.sh @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh -readonly tmux_list_sessions_script="$HOME/.local/bin/tmux_list_sessions.sh" +readonly tmux_list_sessions_script="${HOME}/.local/bin/tmux_list_sessions.sh" export FZF_DEFAULT_OPTS="\ ${FZF_DEFAULT_OPTS} diff --git a/home/user/.local/bin/tmux_list_sessions.sh b/home/user/.local/bin/tmux_list_sessions.sh index 83aaf91..b8627bd 100755 --- a/home/user/.local/bin/tmux_list_sessions.sh +++ b/home/user/.local/bin/tmux_list_sessions.sh @@ -1,15 +1,12 @@ -#!/usr/bin/env bash +#!/bin/sh -declare current_session current_session="$(tmux display-message -p '#S')" readonly current_session -declare last_session last_session="$(tmux display-message -p '#{client_last_session}')" readonly last_session -declare sessions sessions="$(tmux list-session -F '#S#{?session_attached, (attached) , }')" sessions="$(echo "${sessions}" | sed "s/^${current_session} /${current_session} (current) /")" sessions="$(echo "${sessions}" | sed "s/^${last_session} /${last_session} (last) /")" diff --git a/home/user/.local/bin/tmux_start_session.sh b/home/user/.local/bin/tmux_start_session.sh index 2805d4b..9d5b7e2 100755 --- a/home/user/.local/bin/tmux_start_session.sh +++ b/home/user/.local/bin/tmux_start_session.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/bin/sh export FZF_DEFAULT_OPTS="\ diff --git a/home/user/.local/bin/wifi b/home/user/.local/bin/wifi index bf7de6e..2c82126 100755 --- a/home/user/.local/bin/wifi +++ b/home/user/.local/bin/wifi @@ -1,7 +1,7 @@ -#!/bin/bash +#!/bin/sh -set -eo pipefail +set -ue bssid="$(nmcli -f BSSID,SSID,SIGNAL,RATE,BARS,SECURITY dev wifi list | sed -n '1!p' | rofi -dmenu -p "WiFi: " -l 20 | cut -d' ' -f1)" pass="$(echo "" | rofi -dmenu -p "Password: ")" -nmcli device wifi connect "$bssid" "password" "$pass" +nmcli device wifi connect "$bssid" "password" "$pass" \ No newline at end of file