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.
+1 vote
in vifm by
edited by

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?

by
moved by

I think it'd be better to use -ocomm= instead of -ocommand= to prune the extra arguments, otherwise it won't work if vifm summoned with paths or options

1 Answer

+1 vote
by
edited by

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.

by

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

by

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.

...