Reputation: 11813
Is it possible to run new zsh
or bash
shell with custom PS1
set from command line? It should overwrite the default theme set by .bashrc
and .zshrc
respectively.
I'm talking about something like zsh --myprompt="yes master? >"
EDIT: I do not want to affect any user-side configuration files. I want it to work for any user with any configuration.
Upvotes: 5
Views: 1080
Reputation: 154
Create your own "shim" rcfile that's available to your users then call that with the --rcfile
option (for bash) or --rcs
option (for zsh). This should source the user's rcfile first. For example, let's call this /usr/local/share/.fancypromptrc. In bash this might look like:
source "$HOME/.bashrc"
export PS1="DOLLAZ $"
And in zsh this might look like:
source "${ZDOTDIR:-$HOME}/.zshrc"
export PS1="DOLLAZ $"
Then the user would start bash with bash --rcfile /usr/local/share/.fancypromptrc
. In zsh it would be zsh --rcs /usr/local/share/.fancypromptrc
.
This way the user doesn't have to modify their rcfile and if they are already setting PS1 it will still be replaced. The only time I can imagine this not working is if they have a PROMPT_COMMAND that overwrites the PS1, or something similar.
Upvotes: 2
Reputation: 11813
I found the answer. We should just create a dir with custom config files, like .zshrc
:
source $ZDOTDIR_ORIG/.zshrc
export PS1="[x] "$PS1
and then use a script to execute child shell remembering original value of ZDOTDIR
var under ZDOTDIR_ORIG
name, like this pseudopythoncode:
if os.environ.has_key('ZDOTDIR'):
zdotdir = os.environ['ZDOTDIR']
else:
zdotdir = os.path.expanduser('~')
os.environ["ZDOTDIR"] = shellConfPath
os.environ["ZDOTDIR_ORIG"] = zdotdir
And then execute the shell. It will use the config file from ZDOTDIR
directory.
Upvotes: 0
Reputation: 1271
wouldn't export PS1='yes master? >' zsh/bash
work?
I see no reason why it shouldn't be as simple as that and yet achieve what you were after
Upvotes: -1
Reputation: 532093
Anything you do from the command line is likely to be overridden by your configuration files. You'll need to modify the appropriate file slightly to use something like
# *After* you make any changes to PS1
if [[ -n $MY_PS1 ]]; then
PS1=$MY_PS1
fi
If you invoke the shell as
MY_PS1='yes master? > ' bash # or zsh
then MY_PS1
will be used instead of whatever is configured in .{bash,zsh}rc
.
Upvotes: 0