xtermを開くか既存のxtermに切り替えるためのFluxboxショートカット

xtermを開くか既存のxtermに切り替えるためのFluxboxショートカット

Fluxboxを使用して、次のプロパティを使用して端末(つまり、何でも)を開くことができるwinkey+というショートカットを設定できますか?rxterm

  1. タスクディレクトリ=〜の端末がすでに存在し、現在実行中のコマンドがない場合(たとえば、プロンプトで)、この端末が表示されます。
  2. または、新しい端末を作成しない場合

ベストアンサー1

これが私がする方法です:

  1. プロンプトが表示されたら、シェルのタイトルを「bash」に設定し、コマンドを実行するときにコマンド名を「bash」に設定するか、区別する項目を設定します。
  2. 開いているウィンドウのリストを呼び出すスクリプトを作成しwmctrlたら、次の操作を行います。
    • wmctrl「bash」というタイトルのウィンドウが見つかったら、それを上昇させます。
    • それ以外の場合xterm
  3. xbindkeysホットキーを押したときにスクリプトを呼び出すために使用されます。

コマンドを実行するときにシェルにウィンドウのタイトルを設定するようにしてください。

bashでこれを行う方法の単純化されたバージョンは次のとおりです。コードを注意深く確認しませんでしたが、私のコンピュータでは動作します。

# set the title when we run a command
setcommandhook()
{
    if $has_debug_trap
    then
        trap 'command=$BASH_COMMAND; eval settitle "\"${title}\""; trap - DEBUG' DEBUG
    fi
}

# set the xterm title
settitle()
{
    printf "\033]0;$*\007"
}

promptstring='$(hostname):$(pwd)$ '
title='$(hostname) "${command:-$0}"'

# prompt and window title
if test -n "${title}"
then
    PROMPT_COMMAND='command=; eval settitle "\"${title}\""'
    if $has_debug_trap
    then
        PROMPT_COMMAND="$PROMPT_COMMAND; setcommandhook"
    fi
fi
if test -n "${promptstring}"
then
    PS1='$(eval echo -n "\"${promptstring}\"")'
fi

フックがあるので作業がzsh簡単です。preexec

あなたは見ることができますマイシェルの設定getcommandより良い方法でコマンドを処理する機能などの詳細を確認してください。fg


bashプロンプトでxtermを起動し、そうでない場合は新しいプロンプトを起動します。

タイトル付きのウィンドウをwmctrl -l見つけて、ウィンドウを一覧表示するスクリプトを作成します。bash見つかった場合は実行wmctrl -i -a <id returned by wmctrl -l>して発生し、それ以外の場合は呼び出しますxterm

これを行うスクリプトは次のとおりです。

#!/bin/bash
#
# bashprompt
#
# if there is an xterm open at a bash prompt, raise/focus that window
# if there isn't start a new xterm
#
# requires that your xterm window title has "bash" at the end
# when there is no command running and doesn't have "bash" at the end
# when a command is running
#
# see <http://unix.stackexchange.com/questions/6842> for more details
#
# Mikel Ward <[email protected]>

# change this to whatever is unique about your window title
# (i.e. a string that appears in the title when the shell is at a prompt
#  but does not appear when running a command)
prompttitle="bash$"
terminalprog="xterm"

if ! type wmctrl >/dev/null 2>&1; then
    echo "wmctrl can't be found, please install it" 1>&2
    exit 1
fi

if ! output="$(wmctrl -l)"; then
    echo "Error running wmctrl -l" 1>&2
    exit 1
fi
while IFS=$'\n' read -r line; do
    if [[ $line =~ $prompttitle ]]; then
        id=${line%% *}
        break
    fi
done <<EOF
$output
EOF

if test -n "$id"; then
    wmctrl -i -a "$id"
else
    "$terminalprog"&
fi

または私のスクリプトストアからダウンロードしてください。


Win + Rを押すとスクリプトを実行する

スクリプトが呼び出されたとし、次の内容でファイルを作成し/usr/local/bin/bashpromptます。~/.xbindkeysrc

"/usr/local/bin/bashprompt"
    Mod4 + r

それからxbindkeys。これを.Xclientsファイルや類似の項目に追加すると、自動的に起動します。

おすすめ記事