LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-03-2016, 05:56 AM   #1
mostar
LQ Newbie
 
Registered: Jul 2016
Posts: 6

Rep: Reputation: Disabled
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
 
Old 07-03-2016, 09:36 AM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
What have you tried so far?
 
Old 07-03-2016, 11:09 AM   #3
mostar
LQ Newbie
 
Registered: Jul 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
http://unix.stackexchange.com/questi...n-shell-prompt
 
Old 07-03-2016, 11:50 AM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by mostar View Post
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?
 
Old 07-03-2016, 12:28 PM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,780

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
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\\"
 
Old 07-03-2016, 01:02 PM   #6
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by mostar View Post
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*/}'

Last edited by keefaz; 07-03-2016 at 01:04 PM.
 
Old 07-03-2016, 02:25 PM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,780

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Quote:
Originally Posted by keefaz View Post
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.
 
Old 07-03-2016, 06:56 PM   #8
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by MadeInGermany View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
limiting vsftpd user to subdirectory of home directory sniper8752 Linux - Newbie 6 07-29-2014 07:30 AM
[SOLVED] pcmanfm opens subdirectory instead of home directory hilltownboy Linux - Desktop 6 06-10-2012 06:56 PM
vsftpd: Can a local user be restricted to a subdirectory in HOME granduke Linux - Server 1 05-01-2008 08:14 AM
where is my subdirectory blotch Linux - Newbie 22 06-18-2005 11:43 AM
sftp subdirectory how to ?? x2000koh Linux - General 1 12-16-2002 01:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration