From 3ce43395a04de0d66f6616e9012bab09ed4f225b Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 27 Feb 2018 17:38:32 -0500 Subject: [PATCH] Replace rename_workspaces.sh by Python script which behaves better also doesn't require jq --- .config/i3/config | 2 +- .config/i3/rename_workspace.py | 22 ++++++++++++++++++++++ .config/i3/rename_workspace.sh | 13 ------------- 3 files changed, 23 insertions(+), 14 deletions(-) create mode 100755 .config/i3/rename_workspace.py delete mode 100755 .config/i3/rename_workspace.sh diff --git a/.config/i3/config b/.config/i3/config index 51c2f63..050e8af 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -54,7 +54,7 @@ bindsym $mod+space exec --no-startup-id "rofi $rofiOptions -show drun" bindsym $mod+d exec --no-startup-id "rofi $rofiOptions -show run" bindsym $mod+t exec --no-startup-id "rofi $rofiOptions -show sworkspace" bindsym $mod+Shift+t exec --no-startup-id "rofi $rofiOptions -show mworkspace" -bindsym $mod+n exec $config_dir/rename_workspace.sh +bindsym $mod+n exec $config_dir/rename_workspace.py bindsym $mod+c exec --no-startup-id rofi-pass diff --git a/.config/i3/rename_workspace.py b/.config/i3/rename_workspace.py new file mode 100755 index 0000000..85fd0f8 --- /dev/null +++ b/.config/i3/rename_workspace.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +import subprocess +import json +import re + +workspaces = json.loads( + subprocess.check_output(["i3-msg", "-t", "get_workspaces"])) +focused = [ws for ws in workspaces if ws['focused']] + +if len(focused) == 1: # I have no idea when it wouldn't be, but whatever + inputName = subprocess.check_output( + ['rofi', '-dmenu', '-l', '0', '-p', f'New name']).decode().strip() + oldNum = str(focused[0]['num']) + + # basically either take raw input, allow clearing text part of a name, + # or add input to current number + newName = inputName if re.match('^[0-9]+:', inputName) is not None else \ + oldNum if inputName == "" else \ + oldNum + ':' + inputName + + subprocess.call(['i3', "rename", "workspace", "to", newName]) diff --git a/.config/i3/rename_workspace.sh b/.config/i3/rename_workspace.sh deleted file mode 100755 index 5cbfe98..0000000 --- a/.config/i3/rename_workspace.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -num=`i3-msg -t get_workspaces | jq 'map(select(.focused == true))[0].num'` -i3-input -F "rename workspace to \"$num:%s\"" -P "New name: $num:" - -name=`i3-msg -t get_workspaces | jq 'map(select(.focused == true))[0].name'` -# If empty name was set -echo "$name" -if [[ "$name" =~ ^\"[0-9]+:\ *\"$ ]] -then - # Remove trailing comma and whitespace - i3-msg "rename workspace to \"$num\"" -fi