Knowledge Garden

Search

Search IconIcon to open search

Drop Down Terminals

Last updated Nov 2, 2022 Edit Source

kauke

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
[![IntelliJ IDEA](moz-extension://296a2c11-aed0-47f9-845d-6b0d8208628a/intellij-idea.svg)](https://github.com/gotbletu/shownotes/blob/master/any_term_dropdown.sh#)

#!/usr/bin/env bash

# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry)

# https://www.youtube.com/user/gotbletu

# DESC: turn any terminal into a dropdown terminal

# DEMO: https://www.youtube.com/watch?v=mVw2gD9iiOg

# DEPEND: coreutils xdotool wmutils (https://github.com/wmutils/core | https://aur.archlinux.org/packages/wmutils-git/)

# CLOG: 2021-02-10 use comm to match window name and class, this avoids terminal windows with different names

# 2015-02-15 0.1

# get screen resolution width and height

ROOT=$(lsw -r)

width=$(wattr w "$ROOT")

height=$(wattr h "$ROOT")

# option 1: set terminal emulator manually

# my_term=urxvt

# my_term=sakura

my_term="xterm"

# my_term="alacritty"

# my_term=terminator

# my_term=gnome-terminal

# option 2: auto detect terminal emulator (note: make sure to only open one)

# my_term="urxvt|xterm|uxterm|termite|sakura|lxterminal|terminator|mate-terminal|pantheon-terminal|konsole|gnome-terminal|xfce4-terminal"

# get terminal emulator pid ex: 44040485

# pid=$(xdotool search --class "$my_term" | tail -n1)

# get terminal emulator and matching name pid ex: 44040485

pid=$(comm -12 <(xdotool search --name "$my_term" | sort) <(xdotool search --class "$my_term" | sort))

# get windows id from pid ex: 0x2a00125%

wid=$(printf 0x%x "$pid")

# maximize terminal emulator

wrs "$width" "$height" "$wid"

# toggle show/hide terminal emulator

mapw -t "$wid"