Я так часто использую терминал для выполнения быстрых команд, а затем оставляю его в фоновом режиме, чтобы в итоге я получил 20+ сеансов терминала, открытых во время работы. Это потому, что очень быстро просто использовать сочетание клавиш и ввести команду.
Есть ли способ настроить комбинацию клавиш, чтобы я вызывал мое последнее окно терминала вместо создания нового?
Мне прикрепили терминал к моей боковой панели средства запуска Единицы на положении 10. Таким образом, я могу нажать , Супер + 0 для "нажимания" значка средства запуска, который приносит последнее окно терминала к вершине.
При наличии его в средстве запуска хорошо для Вас (одно из первых 10 положений, иначе это не получит ярлык!), это будет работать.
Эта простая команда wmctrl повысит окно с данной строкой в заголовке или если никакое окно не существует содержащий строку, выполните команду.
wmctrl -a <str> || <command to launch application>
, например, для gedit я могу использовать
wmctrl -a gedit || gedit
, Чтобы найти подходящую строку для Вашего окна приложения, открыть Ваше приложение и работать
wmctrl -l
Я использую землетрясение , и я очень доволен им. Нажмите F12, окно терминала появляется, нажмите F12 снова, это исчезает, но продолжает бежать в фоновом режиме. Также: взгляды действительно охлаждаются.
Можно поместить сценарий ниже под сочетанием клавиш. При нажатии сочетания клавиш окно (окна) терминала исчезнет (полностью). Нажмите его снова, они откроются снова точно в состоянии, поскольку у Вас был он.
Только вещь Вы должны к (однажды) должен добавить строку идентификации на название окна Вашего терминала (окно терминала имеет то же имя в большинстве случаев)
Установка и xdotool
и wmctrl
:
sudo apt-get install xdotool
sudo apt-get install wmctrl
hide_terminal.py
Выполнение это под сочетанием клавиш:
python3 /path/to/hide_terminal.py
#!/usr/bin/env python3
import subprocess
import os
home = os.environ["HOME"]
hidden_windowid = home+"/.window_id.txt"
get = lambda cmd: subprocess.check_output(cmd).decode("utf-8")
# --- set the identifying string in the terminal window's name below (you mentioned "Terminal"
window_idstring = "Special_window"
# ---
def execute(cmd):
subprocess.check_call(cmd)
w_id = [l.split()[0] for l in get(["wmctrl", "-l"]).splitlines() if window_idstring in l]
if len(w_id) !=0:
for w in w_id:
execute(["xdotool", "windowunmap", w])
with open(hidden_windowid, "a") as out:
out.write(w+"\n")
else:
try:
with open(hidden_windowid) as read:
for w in [w.strip() for w in read.readlines()]:
try:
execute(["xdotool", "windowmap", w])
except subprocess.CalledProcessError:
pass
with open(hidden_windowid, "wt") as clear:
clear.write("")
except FileNotFoundError:
pass
Это - то же самое как ответ Jacob Vlijm, просто записанный в ударе:
#!/usr/bin/env bash
## window_name will be the first argument passed or, if no
## argument was given, "Terminal"
window_name=${1:-"Terminal"}
## Get the list of open terminals
terms=( $(wmctrl -l | grep "$window_name" | cut -d ' ' -f 1) )
## If all terminals are hidden
if [ -z "${terms[0]}" ]
then
## Read the IDs of hidden windows from .hidden_window_id
while read termid
do
xdotool windowmap "$termid"
done < ~/.hidden_window_id
## If there are visible terminals
else
## Clear the .hidden_window_id file
> ~/.hidden_window_id
## For each open terminal
for i in "${terms[@]}"
do
## Save the current ID into the file
printf "%s\n" "$i" >> ~/.hidden_window_id
## Hide the window
xdotool windowunmap "$i"
done
fi
при сохранении его как ~/bin/show_hide.sh
можно выполнить его путем предоставления строки идентификации любого окна, которое Вы хотите скрыть. Если никакая строка не будет дана, это будет работать над Terminal
:
show_hide.sh Terminal
Я использую gnome-shell
с 'Выпадающим Терминальным' расширением, ярлык по умолчанию TAB
, но это легко изменяется.
следующий подход работал на меня:
#!/usr/bin/env bash
# Written by Eric Zhiqiang Ma (http://www.ericzma.com)
# Last update: Jul. 9, 2014
# Read the tutorials at
# http://www.systutorials.com/5475/turning-gnome-terminal-to-a-pop-up-terminal/
# Required tools: xdotool
terminal="gnome-terminal"
stat_file="/dev/shm/actiavte-termianl.term.$USER"
termtype="Terminal"
wait_sec=1
max_wait_cnt=4
# parse options first
if [ "$1" != "" ]; then
terminal="$1"
fi
term_exists () {
allterms=`xdotool search --class "$termtype"`
for e in $allterms; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
create_terminal () {
echo "Create new terminal"
$terminal --maximize &
exists=1
wait_cnt=0
until [ "$exists" == "0" ]; do
# sleep a while
sleep $wait_sec
# Note that the focus window may be from a terminal that
# already exists; the makes create_terminal choose the existing terminal
# Making the wait_sec large enough so that the terminal can be created and
# displayed can make the false choosing more unlikely.
term=$(xdotool getwindowfocus)
term_exists "$term"
exists=$?
# avoid infinite wait
let wait_cnt=wait_cnt+1
if [ $wait_cnt -gt $max_wait_cnt ]; then
echo "Wait for too long. Give up."
term=""
exists=0
fi
done
echo "Created terminal window $term"
# save the state
echo "$term" >$stat_file
}
# read the state
if [ -f $stat_file ]; then
term=$(cat $stat_file)
fi
# check whether it exists
term_exists "$term"
exists=$?
if [[ "$exists" != "0" ]]; then
create_terminal
exit 0
fi
# check whether it is already activated
curwin=$(xdotool getwindowfocus)
if [ "$term" == "$curwin" ]; then
# deactivate (minimize) the terminal if it is currently activated
xdotool windowminimize $curwin
else
# activate the terminal if it is not currently activated
xdotool windowactivate $term
fi
exit 0
затем просто дают его, выполняют полномочия и связывают сценарий с ключом в настройках.
источник:
http://www.systutorials.com/5475/turning-gnome-terminal-to-a-pop-up-terminal/