diff options
| author | bozo.kopic <bozo@kopic.xyz> | 2020-10-14 23:57:21 +0200 |
|---|---|---|
| committer | bozo.kopic <bozo@kopic.xyz> | 2020-10-14 23:57:21 +0200 |
| commit | a7f6bcbf2930fda0547136491bf1a67c3b337224 (patch) | |
| tree | ac912071501f523741c2629a5ab99d07384f1ded /bspwm/terminal.py | |
| parent | 2dcb41cd467d47a4c867b91cf5b26a4158937e7d (diff) | |
.
Diffstat (limited to 'bspwm/terminal.py')
| -rw-r--r-- | bspwm/terminal.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bspwm/terminal.py b/bspwm/terminal.py new file mode 100644 index 0000000..eee7875 --- /dev/null +++ b/bspwm/terminal.py @@ -0,0 +1,46 @@ +import subprocess + + +desktop_name = 'term' +instance_name = 'tmux_term' + + +def is_term_running(): + p = subprocess.run(['xdo', 'id', '-n', instance_name]) + return p.returncode == 0 + + +def run_term(): + subprocess.Popen(['alacritty', '--class', instance_name, + '-e', 'tmux', 'new-session', '-A', '-s', 'default']) + + +def get_focused_desktop(): + p = subprocess.run(['bspc', 'query', '-D', '--names', '-d', 'focused'], + capture_output=True, + check=True) + return p.stdout.decode('utf-8').strip() + + +def hide_term(): + subprocess.run(['bspc', 'desktop', '-f', 'last.local'], check=True) + + +def show_term(): + subprocess.run(['bspc', 'desktop', 'term', '-m', 'focused']) + subprocess.run(['bspc', 'desktop', '-f', 'term'], check=True) + + +def main(): + if not is_term_running(): + run_term() + + focused_desktop = get_focused_desktop() + if focused_desktop == desktop_name: + hide_term() + else: + show_term() + + +if __name__ == '__main__': + main() |
