Welcome to Vifm Q&A, where you can ask questions about Vifm usage. Registration is optional, anonymous posts are moderated. GitHub or Google logins are enabled.

indicate that shell sessions is running inside vifm

0 votes
asked Aug 17 in vifm by jose1711
edited Aug 17 by xaizek

many times i've been wondering myself if my session (i use plenty of tabs) is "vanilla" or run inside vifm. i've come with this (put into `.zshrc`):

if [ $(ps -ocommand= $(ps -oppid= -p $$)) = "vifm" ]
then
        printf "\e[48;5;21m"
        echo "-- VIFM SHELL SESSION --"
        export PROMPT="-- VIFM_SESSION --"$'\n'"${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)"
fi

so it then looks as follows:

-- VIFM SHELL SESSION --
-- VIFM_SESSION --
➜  ~ uname 
Linux
-- VIFM_SESSION --

slightly different background would probably be better but i am not sure if it could survive commands like `reset` for instance. do you have anything else in mind? maybe this could also go to tips section?

1 Answer

0 votes
answered Aug 17 by xaizek
edited Sep 1 by xaizek

I have it setup differently. In vifmrc:

let $INSIDE_VIFM = 'true'

In .bashrc something similar to this (it's actually more complicated, but
that part doesn't seem to work as expected):

if [ -n "$INSIDE_VIFM" ]; then
    PS1="[V]$PS1"
    unset INSIDE_VIFM
fi

However environment variable might be set to some child, which will then spawn a shell which will think it's in vifm.

maybe this could also go to tips section?

Do you mean on wiki? It's there now.

commented Aug 19 by anonymous

thank you, your solution is definitely cleaner. and yes, i meant wiki.

commented Aug 19 by xaizek

But it has that drawback due to environment variables being inherited, which your solution doesn't have. Yeah, might be worth adding to the tips, maybe both options as they are quite different.

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here is acceptable, but this is not a perfect place for them.
...