Linux ui/ux > macOS
November 18, 2022•283 words
Linux ui/ux improvement past macOS with iTerm
raise_cycle_run
- Specific instructions here for ubuntu based distro using gnome-terminal, though easily adapted
*
dependency: wmctrl
vim /home/\$user/<where ever your local bin>/raise_cycle_run
#!/usr/bin/env bash
# Dependency: sudo apt install wmctrl
# set custom shortcut: raise_cycle_run
# ~/.zmeta/bin/raise_cycle_run gnome-terminal-server "Gnome-terminal" (can vary check with wmctrl -x -l )
if [ $# -ne 2 ]; then
exit 1
fi
count=$(wmctrl -x -l | grep -c "$2")
sanity=$(echo "$2" | tr '[:upper:]' '[:lower:]')
# if the window count is greater or equal to 2 then cycle through focusing the windows
if [[ $count -ge 2 ]]; then
# Get id of the focused window.
active_win_id=$(xprop -root | grep '^_NET_ACTIVE_W' | awk -F'# 0x' '{print $2}')
# Get window manager class of focused window.
win_class=$(wmctrl -x -l | grep "$active_win_id" | awk '{print $2 " " $3}')
# Retrieve list of all windows matching with the class above.
win_list=$(wmctrl -x -l | grep -- "$win_class" | awk '{print $1}')
# Find the next window to focus.
switch_to=$(echo "$win_list" | awk -v active_win_id="$active_win_id" '$0~active_win_id{p=1;next} p{print $1;exit}')
# If the current window is the last in the list, take the first one.
if [ -z "$switch_to" ]; then
switch_to=$(echo "$win_list" | awk 'NR==1{print}')
fi
wmctrl -i -a "$switch_to"
# Else window count is 0 or 1 then call the sanitized window title to invoke an instance
else
$sanity &>/dev/null
fi
chmod +x /home/\$user/<where ever your local bin>/raise_cycle_run
Settings > Keyboard > View and Customize Shortcuts > Custom Shortcuts > +
name: <w/e you want doesn't matter functionally>
Command: <full path to the script> <window class> <window title>
Shortcut: <recommend menu + spacebar or similar>