From 3b393c2fea7819d58819001982c71891f8854fc4 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 10 Mar 2022 11:49:41 -0500 Subject: [PATCH] Re-write some shell scripts to Python with i3ipc --- .config/i3/move_to_workspace.py | 12 ++++++++++++ .config/i3/move_to_workspace.sh | 9 --------- .config/i3/switch_workspace.py | 12 ++++++++++++ .config/i3/switch_workspace.sh | 9 --------- 4 files changed, 24 insertions(+), 18 deletions(-) create mode 100755 .config/i3/move_to_workspace.py delete mode 100755 .config/i3/move_to_workspace.sh create mode 100755 .config/i3/switch_workspace.py delete mode 100755 .config/i3/switch_workspace.sh diff --git a/.config/i3/move_to_workspace.py b/.config/i3/move_to_workspace.py new file mode 100755 index 0000000..e455ec6 --- /dev/null +++ b/.config/i3/move_to_workspace.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import sys + +import i3ipc + +i3 = i3ipc.Connection() + +if len(sys.argv) == 1: + print("\n".join([ws.name for ws in i3.get_workspaces()])) +else: + i3.command("move to workspace {sys.argv[1]}") diff --git a/.config/i3/move_to_workspace.sh b/.config/i3/move_to_workspace.sh deleted file mode 100755 index 3119282..0000000 --- a/.config/i3/move_to_workspace.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -if [ -z "$1" ] -then - i3-msg -t get_workspaces | tr ',' '\n' | grep "name" | sed 's/"name":"\(.*\)"/\1/g' | sort -n -else - i3-msg move to workspace "$1" 1>2 -fi - diff --git a/.config/i3/switch_workspace.py b/.config/i3/switch_workspace.py new file mode 100755 index 0000000..ad06a17 --- /dev/null +++ b/.config/i3/switch_workspace.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import sys + +import i3ipc + +i3 = i3ipc.Connection() + +if len(sys.argv) == 1: + print("\n".join([ws.name for ws in i3.get_workspaces()])) +else: + i3.command("workspace {sys.argv[1]}") diff --git a/.config/i3/switch_workspace.sh b/.config/i3/switch_workspace.sh deleted file mode 100755 index c147b9f..0000000 --- a/.config/i3/switch_workspace.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -if [ -z "$1" ] -then - i3-msg -t get_workspaces | tr ',' '\n' | grep "name" | sed 's/"name":"\(.*\)"/\1/g' | sort -n -else - i3-msg workspace "$1" 1>2 -fi -