Skip to content

Commit

Permalink
shfmt scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Hennigar committed Dec 10, 2024
1 parent 57b680d commit e16875d
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 146 deletions.
4 changes: 2 additions & 2 deletions bin/clam-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

if grep -q open /proc/acpi/button/lid/LID/state; then
swaymsg output eDP-1 enable
swaymsg output eDP-1 enable
else
swaymsg output eDP-1 disable
swaymsg output eDP-1 disable
fi
85 changes: 42 additions & 43 deletions bin/cycle-focus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,57 @@

reverse=""
while getopts "hr" opt; do
case "$opt" in
h|help)
echo "Usage: cycle-focus.sh OPTIONS target [runstring]"
echo
echo "Cycle focus through the windows on the current workspace."
echo
echo "OPTIONS"
echo "-r|--reverse cycle in reverse (NOT YET IMPLEMENTED)"
exit 0
;;
r|reverse)
reverse="set"
;;
esac
case "$opt" in
h | help)
echo "Usage: cycle-focus.sh OPTIONS target [runstring]"
echo
echo "Cycle focus through the windows on the current workspace."
echo
echo "OPTIONS"
echo "-r|--reverse cycle in reverse (NOT YET IMPLEMENTED)"
exit 0
;;
r | reverse)
reverse="set"
;;
esac
done

workspace=$( swaymsg -t get_workspaces |
jq -r '.[] | select(.focused==true) | .name' |
awk -F':' '{print $1}' )
workspace=$(swaymsg -t get_workspaces |
jq -r '.[] | select(.focused==true) | .name' |
awk -F':' '{print $1}')

focused=$( swaymsg -t get_tree | jq '.. | select(.type?) |
select(.focused==true) | .id' )
focused=$(swaymsg -t get_tree | jq '.. | select(.type?) |
select(.focused==true) | .id')

window_ids=($( swaymsg -t get_tree |
jq -r --arg ws $workspace '
window_ids=($(swaymsg -t get_tree |
jq -r --arg ws $workspace '
.. | select(.type?=="workspace" and .name==$ws) |
recurse(.nodes[]) | select(.name != null and .type?=="con") |
.id' ))
.id'))

if [ -n "$reverse" ]; then
min=0
max=$(( ${#window_ids[@]} -1 ))
while [[ min -lt max ]]
do
x="${window_ids[$min]}"
window_ids[$min]="${window_ids[$max]}"
window_ids[$max]="$x"
(( min++, max-- ))
done
min=0
max=$((${#window_ids[@]} - 1))
while [[ min -lt max ]]; do
x="${window_ids[$min]}"
window_ids[$min]="${window_ids[$max]}"
window_ids[$max]="$x"
((min++, max--))
done
fi

if [ -n "$window_ids" ]; then
found_focused=false
for window in "${window_ids[@]}"; do
if $found_focused; then
swaymsg "[con_id=$window] focus"
exit 0
fi
if [ "$window" = "$focused" ]; then
found_focused=true
fi
done
first_window=$(echo "$window_ids" | head -n 1)
swaymsg "[con_id=$first_window]" focus
found_focused=false
for window in "${window_ids[@]}"; do
if $found_focused; then
swaymsg "[con_id=$window] focus"
exit 0
fi
if [ "$window" = "$focused" ]; then
found_focused=true
fi
done
first_window=$(echo "$window_ids" | head -n 1)
swaymsg "[con_id=$first_window]" focus
fi
23 changes: 12 additions & 11 deletions bin/fuzzel-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
cd $HOME
file=1
while [ "$file" ]; do
file=$(ls -1 --group-directories-first | fuzzel -d -p "$(basename $(pwd))")
if [ -e "$file" ]; then
owd=$(pwd)
if [ -d "$file" ]; then
cd "$file"
else [ -f "$file" ]
if which xdg-open &> /dev/null; then
exec xdg-open "$owd/$file" &
unset file
fi
file=$(ls -1 --group-directories-first | fuzzel -d -p "$(basename $(pwd))")
if [ -e "$file" ]; then
owd=$(pwd)
if [ -d "$file" ]; then
cd "$file"
else
[ -f "$file" ]
if which xdg-open &>/dev/null; then
exec xdg-open "$owd/$file" &
unset file
fi
fi
fi
fi
done
49 changes: 24 additions & 25 deletions bin/new-workspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,37 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

while getopts "hdt" opt; do
case "$opt" in
h|help)
echo "Usage: new-workspace.sh [OPTIONS]"
echo "Switch to the lowest unused workspace."
echo
echo "OPTIONS"
echo "-t, --take-focused take the current window with you"
exit 0
;;
d|debug)
debug="1"
shift
;;
t|take-focused)
take=$( swaymsg -t get_tree |
jq '.. | select(.type?) | select(.focused==true) | .id' )
shift
;;
case "$opt" in
h | help)
echo "Usage: new-workspace.sh [OPTIONS]"
echo "Switch to the lowest unused workspace."
echo
echo "OPTIONS"
echo "-t, --take-focused take the current window with you"
exit 0
;;
d | debug)
debug="1"
shift
;;
t | take-focused)
take=$(swaymsg -t get_tree |
jq '.. | select(.type?) | select(.focused==true) | .id')
shift
;;
esac
done

workspaces=($( swaymsg -t get_workspaces | jq -r '.[].num' | sort -n ))
workspaces=($(swaymsg -t get_workspaces | jq -r '.[].num' | sort -n))
next_workspace=$(echo "${workspaces[@]}" |
awk -v RS='\\s+' '
awk -v RS='\\s+' '
{ a[$1] } END { for(i = 1; i in a; ++i); print i }')

[[ "$debug" ]] && {
for i in ${workspaces[@]}
do
echo "WORKSPACES: $i"
done
echo "NEXT: $next_workspace"
for i in ${workspaces[@]}; do
echo "WORKSPACES: $i"
done
echo "NEXT: $next_workspace"
}

[[ "$take" ]] && swaymsg "move window to workspace $next_workspace"
Expand Down
2 changes: 1 addition & 1 deletion bin/run-or-raise.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

swaymsg "[app_id=$1] focus" >/dev/null 2>&1 || {
swaymsg "[class=$1] focus" >/dev/null 2>&1 || {
swaymsg exec "$2"
swaymsg exec "$2"
}
}
16 changes: 6 additions & 10 deletions bin/screenshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

for prog in grim slurp; do
if which "$prog" &> /dev/null; then
grim -g "$(slurp)"
notify-send -t 3000 "Screenshot" "Saved in $GRIM_DEFAULT_DIR"
else
notify-send "Install GRIM and SLURP."
fi
if which "$prog" &>/dev/null; then
grim -g "$(slurp)"
notify-send -t 3000 "Screenshot" "Saved in $GRIM_DEFAULT_DIR"
else
notify-send "Install GRIM and SLURP."
fi
done




24 changes: 12 additions & 12 deletions bin/select-theme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ if [[ -n "$1" ]]; then
theme="$1"
else
theme=$(echo -e "day\nnight\nmorning\nbright\nacme" |
fuzzel -d -l 6 -p "Select theme > ");
fuzzel -d -l 6 -p "Select theme > ")
fi

case $theme in
day)
day)
cp ~/.config/alacritty/themes/tomorrow-day.toml \
~/.config/alacritty/colors.toml
~/.config/alacritty/colors.toml
gsettings set org.gnome.desktop.interface gtk-theme Mint-Yz-Base-Grey
gsettings set org.gnome.desktop.interface color-scheme prefer-light
emacsclient -e "(load-theme-disable-others 'drh-tomorrow-day)"
Expand All @@ -43,9 +43,9 @@ case $theme in
sed -i '/^selection-match=/c\selection-match=c82829ff' ~/.config/fuzzel/fuzzel.ini
sed -i '/^counter=/c\counter=8e908cff' ~/.config/fuzzel/fuzzel.ini
;;
night)
night)
cp ~/.config/alacritty/themes/tomorrow-night.toml \
~/.config/alacritty/colors.toml
~/.config/alacritty/colors.toml
gsettings set org.gnome.desktop.interface gtk-theme Mint-Yz-Dark-Grey
gsettings set org.gnome.desktop.interface color-scheme prefer-dark
emacsclient -e "(load-theme-disable-others 'drh-tomorrow-night)"
Expand All @@ -61,9 +61,9 @@ case $theme in
sed -i '/^selection-match=/c\selection-match=cc6666ff' ~/.config/fuzzel/fuzzel.ini
sed -i '/^counter=/c\counter=969896ff' ~/.config/fuzzel/fuzzel.ini
;;
morning)
morning)
cp ~/.config/alacritty/themes/tomorrow-morning.toml \
~/.config/alacritty/colors.toml
~/.config/alacritty/colors.toml
gsettings set org.gnome.desktop.interface gtk-theme Mint-Yz-Base-Grey
gsettings set org.gnome.desktop.interface color-scheme prefer-light
emacsclient -e "(load-theme-disable-others 'drh-tomorrow-morning)"
Expand All @@ -79,9 +79,9 @@ case $theme in
sed -i '/^selection-match=/c\selection-match=c82829ff' ~/.config/fuzzel/fuzzel.ini
sed -i '/^counter=/c\counter=8e908cff' ~/.config/fuzzel/fuzzel.ini
;;
bright)
bright)
cp ~/.config/alacritty/themes/tomorrow-bright.toml \
~/.config/alacritty/colors.toml
~/.config/alacritty/colors.toml
gsettings set org.gnome.desktop.interface gtk-theme Mint-Yz-Dark-Grey
gsettings set org.gnome.desktop.interface color-scheme prefer-dark
emacsclient -e "(load-theme-disable-others 'drh-tomorrow-bright)"
Expand All @@ -97,9 +97,9 @@ case $theme in
sed -i '/^selection-match=/c\selection-match=d54e53ff' ~/.config/fuzzel/fuzzel.ini
sed -i '/^counter=/c\counter=969896ff' ~/.config/fuzzel/fuzzel.ini
;;
acme)
acme)
cp ~/.config/alacritty/themes/acme.toml \
~/.config/alacritty/colors.toml
~/.config/alacritty/colors.toml
gsettings set org.gnome.desktop.interface gtk-theme Mint-Yz-Base-Grey
gsettings set org.gnome.desktop.interface color-scheme prefer-dark
emacsclient -e "(load-theme-disable-others 'drh-mono-acme)"
Expand All @@ -114,5 +114,5 @@ case $theme in
sed -i '/^selection-text=/c\selection-text=4d4d4cff' ~/.config/fuzzel/fuzzel.ini
sed -i '/^selection-match=/c\selection-match=c82829ff' ~/.config/fuzzel/fuzzel.ini
sed -i '/^counter=/c\counter=8e908cff' ~/.config/fuzzel/fuzzel.ini
;;
;;
esac
Loading

0 comments on commit e16875d

Please sign in to comment.