LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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
Senior Member
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 18.2 MATE
Posts: 3,482
Blog Entries: 2

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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
Senior Member
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 18.2 MATE
Posts: 3,482
Blog Entries: 2

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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
Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 383

Rep: Reputation: 172Reputation: 172
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: 5,388

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
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
Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 383

Rep: Reputation: 172Reputation: 172
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: 5,388

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:51 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration