1

I'd like to choose whether or not to load zsh plugins if the shell is, at the moment, being run within Dolphin. Is this possible?

I've considered:

  • ps: ps, at least without any flags, does not seem to offer useful information
  • xdotool: xdotool can search for a window named Dolphin, but I don't think that it reports on the current window
  • environment variables: there are some env vars set up for Konsole in general ($KONSOLE_DBUS_SESSION, etc), but none for Dolphin
3
  • If it works in the same manner as most other such situations I've seen, you could look at pstree. You could also look at parsing the output of ps and follow the PPID (PID of the parent process) up the tree to see whether or not you wend your way to Dolphin befure you hit PID 1. Commented May 2, 2024 at 23:16
  • I'd expect to be able to tell fromecho "=== id ===";id;echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias in each of your environments. Commented May 2, 2024 at 23:27
  • Find your Parent's PID at /proc/$$/PPID, read man proc, follow the chain of Parent's Parent's ... up, looking at /proc/*/exe as you go. Commented May 2, 2024 at 23:33

1 Answer 1

0

As long as you just want to know whether the shell is directly run within Dolphin's integrated terminal, it's simple: check the of the parent process.

if [[ $(ps -o comm= -p $PPID) == dolphin ]]; then …

The comm field is the executable's base name.

If you also want to detect nested shells (for example running zsh inside zsh, or :shell inside Vim), it's more complicated. You can check whether the output of pstree -p $$ -s contains dolphin, which will tell you whether Dolphin was involved at any level. This will report false positives, for example, if you start another terminal emulator from inside Dolphin.

Dolphin implements several terminal identification control sequences such as CSI > Ps p but the output is the same as in Konsole. CSI > Ps q is not supported, at least by default (and this is justified because it's a security risk since it can inject arbitrary content into the command line). So I don't think you can get the information that way.

Some GUI terminals set the WINDOWID environment variable to their window ID. Dolphin's integrated terminal sets WINDOWID to 0. This might be weird enough to be a useful indicator: terminal emulators generally either don't set WINDOWID at all or set it to an actual window ID (e.g. xterm and konsole do it). Note that WINDOWID carries the risk that it remains set when you start a terminal emulator from another terminal emulator, for example it can get carried into a screen or tmux session.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.