summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorUrbain Vaes <urbain@vaes.uk>2015-12-19 16:55:46 +0000
committerUrbain Vaes <urbain@vaes.uk>2015-12-19 16:55:46 +0000
commit1303e21f431bc49bba6dc275053d516da0392e54 (patch)
tree79bc4d02a43a13828b703383404cbc1745a60aff /bin
parent64cfb306cc543fd28d2cb3ce7adadad15a8d96e6 (diff)
Fix script for i3 workspaces
Diffstat (limited to 'bin')
-rwxr-xr-xbin/helper_workspace19
-rwxr-xr-xbin/move_workspace19
-rwxr-xr-xbin/workspace24
3 files changed, 53 insertions, 9 deletions
diff --git a/bin/helper_workspace b/bin/helper_workspace
new file mode 100755
index 0000000..77be45d
--- /dev/null
+++ b/bin/helper_workspace
@@ -0,0 +1,19 @@
+#!/bin/zsh
+
+workspaces=$(i3-msg -t get_workspaces | grep -Po '"name":.*?[^\\]"' | sed 's/"name":"\([^"]\+\)"/\1/g')
+
+if [[ ! -z $1 ]]; then
+ target=$(echo $workspaces | grep "$1")
+ [[ -z $target ]] && target=$1
+else
+ used_numbers=$(echo $workspaces | awk 'BEGIN { FS = ":" } ; { print $1 }')
+ max_number=$(echo $used_numbers | tail -1)
+ lowest_gap=$(echo $used_numbers | awk '$1!=p+1{print p+1}{p=$1}' | head -1)
+ [[ -z $lowest_gap ]] && new_number=$(($max_number + 1)) || new_number=$lowest_gap
+
+ target=$(echo $workspaces | dmenu -i -sf green -p "Go to workspace:")
+ [[ -z $target ]] && exit
+ [[ ! $target = [0-9]* ]] && target=$new_number:$target
+fi
+
+echo $target
diff --git a/bin/move_workspace b/bin/move_workspace
new file mode 100755
index 0000000..ab926e0
--- /dev/null
+++ b/bin/move_workspace
@@ -0,0 +1,19 @@
+#!/bin/zsh
+
+workspaces=$(i3-msg -t get_workspaces | grep -Po '"name":.*?[^\\]"' | sed 's/"name":"\([^"]\+\)"/\1/g')
+
+if [[ ! -z $1 ]]; then
+ target=$(echo $workspaces | grep "$1")
+ [[ -z $target ]] && target=$1
+else
+ used_numbers=$(echo $workspaces | awk 'BEGIN { FS = ":" } ; { print $1 }')
+ max_number=$(echo $used_numbers | tail -1)
+ lowest_gap=$(echo $used_numbers | awk '$1!=p+1{print p+1}{p=$1}' | head -1)
+ [[ -z $lowest_gap ]] && new_number=$(($max_number + 1)) || new_number=$lowest_gap
+
+ target=$(echo $workspaces | dmenu -i -sf green -p "Go to workspace:")
+ [[ -z $target ]] && exit
+ [[ ! $target = [0-9]* ]] && target=$new_number:$target
+fi
+
+exec i3-msg workspace $target
diff --git a/bin/workspace b/bin/workspace
index 73a4ec4..a66e0b5 100755
--- a/bin/workspace
+++ b/bin/workspace
@@ -1,14 +1,20 @@
#!/bin/zsh
workspaces=$(i3-msg -t get_workspaces | grep -Po '"name":.*?[^\\]"' | sed 's/"name":"\([^"]\+\)"/\1/g')
-# used_numbers=$(echo $workspaces | awk 'BEGIN { FS = ":" } ; { print $1 }')
-# max_number=$(echo $used_numbers | tail -1)
-# largest_gap=$(echo $used_numbers | awk '$1!=p+1{print p+1}{p=$1}')
-# [[ -z $largest_gap ]] && new_number=$(($max_number + 1)) || new_number=$largest_gap
-# target=$(echo $workspaces | dmenu -i -sf green -p "Go to workspace:")
-# [[ -z $target ]] && exit
-# [[ ! $target = [0-9]* ]] && target=$new_number:$target
+if [[ ! -z $2 ]]; then
+ target=$(echo $workspaces | grep "$2")
+ [[ -z $target ]] && target=$2
+else
+ used_numbers=$(echo $workspaces | awk 'BEGIN { FS = ":" } ; { print $1 }')
+ max_number=$(echo $used_numbers | tail -1)
+ lowest_gap=$(echo $used_numbers | awk '$1!=p+1{print p+1}{p=$1}' | head -1)
+ [[ -z $lowest_gap ]] && new_number=$(($max_number + 1)) || new_number=$lowest_gap
-target=$(echo $workspaces | dmenu -i -sf green -p "Go to workspace:")
-exec i3-msg workspace $target
+ target=$(echo $workspaces | dmenu -i -sf green -p "Go to workspace:")
+ [[ -z $target ]] && exit
+ [[ ! $target = [0-9]* ]] && target=$new_number:$target
+fi
+
+[[ $1 = 'n' ]] && cmd="workspace" || cmd="move container to workspace"
+exec i3-msg $cmd $target