端末のタイトルにはsudoと呼ばれていますが、sudoコマンドを実行したいと思います。

端末のタイトルにはsudoと呼ばれていますが、sudoコマンドを実行したいと思います。

だから私はここですべての投稿を編集することから質問に答えることまで、私の仕事を本当にうまくやってきたので、今質問する必要がある時だと思いました。

技術情報

ディストリビューション:Gentoo
デスクトップ環境:KDE
ターミナルエミュレータ:Kterm

質問

Gentooを長く使ってきた人なら、ターミナルとソースコードの流れに慣れるでしょう。そのため、KDEでも次のコマンドを使用して端末に依存し始めました。

  • kdesudo kate /etc/portage/make.conf
  • sudo emerge -uDav world

コマンドは期待どおりに機能します。問題はktermのタイトル表示です。username:sudo ユーザー名:sudo 昇格されたコマンドまたはユーザー名:elevated コマンドを表示したいと思います。

次の構成ファイルを使用します。

# /etc/profile: login shell setup
#
# That this file is used by any Bourne-shell derivative to setup the
# environment for login shells.
#

# Load environment settings from profile.env, which is created by
# env-update from the files in /etc/env.d
if [ -e /etc/profile.env ] ; then
    . /etc/profile.env
fi

# You should override these in your ~/.bashrc (or equivalent) for per-user
# settings.  For system defaults, you can add a new file in /etc/profile.d/.
export EDITOR=${EDITOR:-/bin/nano}
export PAGER=${PAGER:-/usr/bin/less}

# 077 would be more secure, but 022 is generally quite realistic
umask 022

# Set up PATH depending on whether we're root or a normal user.
# There's no real reason to exclude sbin paths from the normal user,
# but it can make tab-completion easier when they aren't in the
# user's PATH to pollute the executable namespace.
#
# It is intentional in the following line to use || instead of -o.
# This way the evaluation can be short-circuited and calling whoami is
# avoided.
if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then
    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}"
else
    PATH="/usr/local/bin:/usr/bin:/bin:${PATH}"
fi
export PATH
unset ROOTPATH

if [ -n "${BASH_VERSION}" ] ; then
    # Newer bash ebuilds include /etc/bash/bashrc which will setup PS1
    # including color.  We leave out color here because not all
    # terminals support it.
    if [ -f /etc/bash/bashrc ] ; then
        # Bash login shells run only /etc/profile
        # Bash non-login shells run only /etc/bash/bashrc
        # Since we want to run /etc/bash/bashrc regardless, we source it 
        # from here.  It is unfortunate that there is no way to do 
        # this *after* the user's .bash_profile runs (without putting 
        # it in the user's dot-files), but it shouldn't make any 
        # difference.
        . /etc/bash/bashrc
    else
        PS1='\u@\h \w \$ '
    fi
else
    # Setup a bland default prompt.  Since this prompt should be useable
    # on color and non-color terminals, as well as shells that don't
    # understand sequences such as \h, don't put anything special in it.
    PS1="${USER:-$(whoami 2>/dev/null)}@$(uname -n 2>/dev/null) \$ "
fi

for sh in /etc/profile.d/*.sh ; do
    [ -r "$sh" ] && . "$sh"
done
unset sh

etc/bashrc/bashrc家に来たら、ここにファイルを挿入します...


ここに新しいユーザーに回答を提供するためにコメントを残します。したがって、ここに初めて来た場合でも、最も徹底的かつ有効な回答のスコアを得ることができます。注資料とリンクを含む正しい形式の回答が必要です。

修正する

ketem イメージ

ベストアンサー1

確かではありませんが、ktermおそらくxtermエスケープ互換でしょう。ほとんどはそうです。その場合は、プロンプトに何かを追加する必要があります。ウィンドウタイトルの設定:

  • 3.1 xtermエスケープシーケンス

  • XTermエスケープシーケンスを使用して、実行中のxterm内でウィンドウとアイコンのタイトルを変更できます。この点に関して、次の順序が有用である。

    • ESC]0;stringBEL- アイコン名とウィンドウのタイトルを文字列に設定します。
    • ESC]1;stringBEL- アイコン名を文字列に設定します。
    • ESC]2;stringBEL- ウィンドウのタイトルを文字列に設定
  • ...ここではESCエスケープ文字(\033)、BELベル文字(\007)です。

印刷されないエスケープの間にプロンプ​​トに入れることができます。bashそのシェルで次のものを使用できます。

PS1="\[$(printf '\033]0;"${USER}@${BASH_COMMAND}"\007')\]"

あるいは、そのようなものを$PROMPT_COMMAND環境変数に入れることもできます。

しかし...

確かに konsoleバージョンは、ウィンドウ名がエスケープシーケンスを介して設定できるかどうかによって異なります。バージョン3サイクルのいずれかの時点でシーケンス解析を中止し、タブタイトルを変更したときにESC]33;Window nameBELシーケンスのみが尊重されました。xterm

~からバージョン 4.9それでも、konsole少なくとも奇妙なESC]30;Tab NameBEL順序に従う必要があります。 [設定]ダイアログボックスで空になるように設定すると、ウィンドウ名は[現在アクティブ]タブで自動的に複製されます。

xtermウィンドウのタイトルを設定するためにより一般的なエスケープを使用できるかどうかはわかりません。ただし、ここで提供されている情報が満足のいく解決策に到達するのに十分でない場合は、バージョン4.9に文書化されている関連する変更に添付されているリンクをクリックすると、有用な情報を見つけることができると思います。ここで変更履歴を確認してください。

おすすめ記事