Created
April 18, 2019 13:05
-
-
Save jjrh/f9e14575e887f961edff7fe8a39560a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: Justin Hornosty (jjrh) | |
# Date: 2015-10-08 | |
# | |
# jump_remember.sh | |
# --------------------------- | |
# desc: | |
# Remembers a window or jumps to a remembered window. | |
# | |
# usage: | |
# $ jump_remember.sh -r -i1 <-- remembers a window | |
# $ jump_remember.sh -j -i1 <-- jump to a remembered window | |
# | |
# __index MUST start at 1__ | |
# | |
# setup as C-0 for jump, C-S-0 for remembering in openbox. | |
# | |
# <!-- Jump remember 0 --> | |
# <keybind key="C-0"> | |
# <action name="Execute"> | |
# <command>/home/jjrh/bin/jump_remember.sh -j -i1</command> | |
# </action> | |
# </keybind> | |
# | |
# <keybind key="C-S-0"> | |
# <action name="Execute"> | |
# <command>/home/jjrh/bin/jump_remember.sh -r -i1</command> | |
# </action> | |
# </keybind> | |
remember_file=~/tmp/window_remembering | |
JUMP="0" | |
INDEX="-1" | |
REMEMBER="0" | |
while getopts ":i:jr" opt; do | |
case $opt in | |
i) | |
#echo "-i was triggered, Parameter: $OPTARG" >&2 | |
INDEX=$OPTARG | |
;; | |
j) | |
#echo "-j was toggled $OPTARG" | |
JUMP=1 | |
;; | |
r) | |
#echo "-r was toggled $OPTARG" | |
REMEMBER=1 | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
esac | |
done | |
# check that we didn't toggle both jump and remember... | |
if [ $JUMP -eq 1 ] && [ $REMEMBER -eq 1 ] | |
then | |
echo "Cannot 'jump' AND 'remember'... exiting -1" >&2 | |
exit -1 | |
fi | |
# check that we toggled at least jump or remember | |
if [ $JUMP -eq 0 ] && [ $REMEMBER -eq 0 ] | |
then | |
echo "neither 'jump' nor 'remember' were specified... exiting -1 " >&2 | |
exit -1 | |
fi | |
# check if file exists | |
if ! [ -a $remember_file ] | |
then | |
touch $remember_file | |
echo "" > $remember_file | |
fi | |
# make sure we can actually place something in the index. if not | |
# we do a loop with empty lines | |
file_line_count=$(wc -l $remember_file | cut -f1 -d' ') | |
if [ $file_line_count -lt $INDEX ] | |
then | |
for i in $(seq $file_line_count $INDEX) | |
do | |
sed -i "${i}s/.*/\n/" $remember_file | |
done | |
fi | |
######################### | |
# MODE REMEMBER | |
######################### | |
if [ $REMEMBER -eq 1 ] && [ $INDEX -gt -1 ] #] | |
then | |
WINDOW_ID=$(xwininfo | grep "Window id" | cut -d " " -f4) | |
sed -i "${INDEX}s/.*/$WINDOW_ID/" $remember_file | |
# echo "MODE: REMEMBER" | |
# echo "INDEX:$INDEX" | |
fi | |
######################### | |
# MODE JUMP | |
######################### | |
if [ $JUMP -eq 1 ] && [ $INDEX -gt -1 ] #] | |
then | |
id=$(sed -n ${INDEX}p $remember_file) | |
wmctrl -i -a "$id" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment