Bringing $PS1 into scope for script

I’m working on a script that shortens my prompt when I’m deep in a directory tree. I think it will run correctly once I source it into my prompt theme, but till then I’m keeping it separate to avoid breaking the prompt’s appearance. How can I go about passing $PS1 to the script while keeping all variables within $PS1 in scope?

1 Like

I like the concept of this, but don’t have anything helpful at the moment. When I get back to my computer, I’ll look into it.

Not sure how to help.

Bump for anyone that might.

Also OP, have you looked at the Fish shell? It does this already.

you just have to bring the script into scope by running with script with .

EX: . ./script.sh

after that the script should be able to edit the shells current session. just add the script to run whenever bash is executed

1 Like

Yeah, I have. I have a plugin that does the FIsh style directory shortening. The only issue is I’m working on making the shortening dependent on the actual column size of the terminal.

I think I could typeset all of the oh my zsh theme’s variables. I’m just worried that might have unintended consequences.

I’m going to be running . ./script.sh from within the script when I’m finished testing the script. I just wanted to check if there was another way to have the same effect while running ./script.sh $PS1.

I didn’t try it and it’s been ages since using Bash like this, but with PROMPT_COMMAND you could maybe do abbrevd_cwd=$(cwd_condenser_script) or something…

then instead of /w or /W in PS1 use $abbrevd_cwd

Fish is the future of shells, it’s approach to prompts is a good example of it’s design ideology

How’s it compare to zsh?

1 Like

This man gets it.

Seriously though, I’ve always just assumed fish was a meme because all the people on /r/unixporn and the mac hipsters use it. I never really gave it the time of day. I’d love an overview.

If your only objective is just shortening the path to the current folder, you might want to try Powerline (right terminal on the pic below)

imagen

maybe I’m a different person than when I tried ZSH but Fish just works nicer, when researching how to do things the developers attitude was very good and I’d be reading some interesting debates about why he didn’t want to implement a feature like another shell does it etc. It may be slower in many many cases but it’s holding the interface to a standard rather than saying ‘we can’t/must do this cos POSIX or C’, I also like the auto indenting multi line interface with colors so you can easily see escaping and quoting and bypass an editor entirely, universal variable scope for sharing between processes, event bus is currently weak but not useless, string handing is far less annoying.

I was glad I didn’t let that stop me trying it, really does feel more efficient