Last active
February 3, 2020 06:52
-
-
Save ayosec/2e1ece0a217761882cb3979b995562d1 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/wish | |
package require json | |
# Data from current window | |
set window [ | |
json::json2dict [ | |
exec i3-msg -t get_tree \ | |
| jq ".. | (.nodes? // empty)\[] | select(.focused == true)" | |
] | |
] | |
set win_id [dict get $window id] | |
if {[dict exists $window title_format]} { | |
set title [dict get $window title_format] | |
} else { | |
set title "%title" | |
} | |
# Ask for new title | |
tk scaling 5 | |
wm attributes . -type dialog | |
wm title . "Edit title for <[dict get $window name]>" | |
. configure -bg #022 | |
entry .input \ | |
-textvar title \ | |
-bd 0 \ | |
-bg white \ | |
-fg black \ | |
-font monospace \ | |
-width 50 | |
proc cursor_to_quote {} { | |
global title | |
.input selection clear | |
.input icursor [expr [string first \" $title] + 1] | |
} | |
bind .input <Key-Escape> { exit 1 } | |
bind .input <Key-F1> { | |
set title "<span color=\"\">$title</span>" | |
cursor_to_quote | |
} | |
bind .input <Key-F2> { | |
set title "<span color=\"\" background=\"\">$title</span>" | |
cursor_to_quote | |
} | |
bind .input <Key-Return> { | |
if {[expr [string length $title] == 0]} { | |
set title "%%title" | |
} | |
exec i3-msg \[con_id=$win_id] "title_format [exec jq -R . <<$title]" | |
exit | |
} | |
pack .input -fill both -expand 1 -padx 20 -pady 20 | |
focus .input | |
.input selection range 0 [string length $title] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment