Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run new zsh and bash shells with custom as command line agrument

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.

like image 270
Wojciech Danilo Avatar asked Nov 10 '22 10:11

Wojciech Danilo


1 Answers

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.

like image 56
Harmony Orb Avatar answered Nov 15 '22 06:11

Harmony Orb