Is it possible to specify a bash prompt using a command line parameter?

I use vim a lot and often find it useful to get to the command line with !bash. However, I need to dial exitto return to vim, and sometimes I'm not sure if I'm in a subshell or close the session.

I would really like to type !bash -prompt "subshell"something like this to get something like this:

subshell$ <commands go here>

Is it possible?

+5
source share
7 answers

The most direct way to do this is to set the environment variable PS1in vim:

:let $PS1="subshell$ "

And run your sub-shells using the command :shellinstead :!bash.

$ let . .vimrc, .

, :shell, , , , . help shell help 'shell'.

:

:set shell=bash\ --rcfile\ ~/.vimbashrc

.vimbashrc PS1="subshell " - :shell !bash. .vimrc, .

, :

  • let $PS1="subshell " .vimrc - :shell :!bash.
  • rc - vim, PS1="subshell " shell .vimrc: set shell=bash\ --rcfile\ ~/.vimbashrc.

, :!bash -, . , !, :

  • :PS1="subshell$ " bash .
  • :!bash\ --rcfile\ ~/.vimbashrc PS1 .vimbashrc,

.

+9

$SHLVL . $SHLVL $PS1:

export PS1="$PS1 $SHLVL"

:

[tim@RackAblade47 ~]$ 2

VIM, $SHLVL :

[tim@RackAblade47 ~]$ 4
+5

-

PS1 = ""

http://www.linuxselfhelp.com/howtos/Bash-Prompt/Bash-Prompt-HOWTO-2.html

bash, "-rcfile", RC , PS1 ( PS1 = .bashrc, )

+1

, Vim:

:!VIMPROMPT="(vim) " bash

(, .bashrc), ,

PS1='\u@\h:\w\$ '

PS1='$VIMPROMPT\u@\h:\w\$ '

me@host:~$ 

(vim) me@host:~$ 

Vim.

+1

case $(ps $PPID) in *vim|*bash)
  PS1="$(ps $PPID | awk '{print $NF}' | sed 1d) $PS1" ;;
esac

prompt script, . bashrc, triplee comment.

0

.bashrc PS1=.

if ps | grep -q vim; then
  export PS1="[VIM]$PS1"
fi

Tested on Ubuntu.

-1
source

You can send it to the background using CTRL + Z, and then return it using the command fg. With the help jobsyou will see all the tasks that you stopped.

You can have multiple vim instances in parallel and choose which one you want to return. If there is no start, you just get an error no current joband that is.

This does not specifically answer your question, but solves the problem under it.

-2
source

All Articles