LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   The last subdirectory of $HOME (https://www.linuxquestions.org/questions/linux-newbie-8/the-last-subdirectory-of-%24home-4175583652/)

mostar 07-03-2016 05:56 AM

The last subdirectory of $HOME
 
Following this post:
http://www.linuxquestions.org/questi...09#post5569609

I want to set PROMPT_COMMAND so the it will contain only the last subdirectory of $HOME.

Right now its:

Code:

PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${PWD/#$HOME/~}"'
I'm looking for some thing like the difference between:

Code:

export PS1="\u@\W>"
Code:

export PS1="\u@\w>"

Thank you

hydrurga 07-03-2016 09:36 AM

What have you tried so far?

mostar 07-03-2016 11:09 AM

http://unix.stackexchange.com/questi...n-shell-prompt

hydrurga 07-03-2016 11:50 AM

Quote:

Originally Posted by mostar (Post 5569809)

That doesn't seem to be what you're aiming for though. You said that you wanted "to set PROMPT_COMMAND so the it will contain only the last subdirectory of $HOME."

By the way, which shell are you using? Have you looked at basename?

MadeInGermany 07-03-2016 12:28 PM

Adding basename
Code:

PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" `basename "${PWD/#$HOME/~}"`'
Setting the PS1 seems simpler
Code:

unset PROMPT_COMMAND
PS1="\033k\u@\W:\033\\"


keefaz 07-03-2016 01:02 PM

Quote:

Originally Posted by mostar (Post 5569662)
Following this post:
http://www.linuxquestions.org/questi...09#post5569609

I want to set PROMPT_COMMAND so the it will contain only the last subdirectory of $HOME.

Something like this?
Code:

PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" ${PWD##$HOME*/}'

MadeInGermany 07-03-2016 02:25 PM

Quote:

Originally Posted by keefaz (Post 5569863)
Something like this?
Code:

PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" ${PWD##$HOME*/}'

I think you mean
Code:

PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" ${PWD##*/}'
I.e. reduce all pathnames, not only the ones that start with the value of $HOME.
But the own homedir is not printed as ~ then.

keefaz 07-03-2016 06:56 PM

Quote:

Originally Posted by MadeInGermany (Post 5569891)
I think you mean
Code:

PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" ${PWD##*/}'
I.e. reduce all pathnames, not only the ones that start with the value of $HOME.
But the own homedir is not printed as ~ then.

No I meant to just reduce the ones with $HOME :)

Quote:

Originally Posted by mostar
I want to set PROMPT_COMMAND so the it will contain only the last subdirectory of $HOME.



All times are GMT -5. The time now is 10:50 AM.