How to produce a PS1 prompt in bash or ksh93 similar to tcsh
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
In tcsh, I have the default:
prompt [%m:%c3] %n%#
which gives prompts like:
[woehler:hacking/c/hello] ajcarr%
and
[woehler:~] ajcarr%
In other words, the current directory and up to the next two above it in the path.
In ksh93 or bash, the substitution of $HOME
by ~
is easy, as is extracting the name of just the current directory, but I have yet to find a way of replicating the %c3
behaviour of tcsh. At present in ksh93 I have:
[ajcarr@Woehler] hello $
and
[ajcarr@Woehler] ~ $
Does anyone have any suggestions about how to do this?
bash ksh prompt tcsh
add a comment |
In tcsh, I have the default:
prompt [%m:%c3] %n%#
which gives prompts like:
[woehler:hacking/c/hello] ajcarr%
and
[woehler:~] ajcarr%
In other words, the current directory and up to the next two above it in the path.
In ksh93 or bash, the substitution of $HOME
by ~
is easy, as is extracting the name of just the current directory, but I have yet to find a way of replicating the %c3
behaviour of tcsh. At present in ksh93 I have:
[ajcarr@Woehler] hello $
and
[ajcarr@Woehler] ~ $
Does anyone have any suggestions about how to do this?
bash ksh prompt tcsh
add a comment |
In tcsh, I have the default:
prompt [%m:%c3] %n%#
which gives prompts like:
[woehler:hacking/c/hello] ajcarr%
and
[woehler:~] ajcarr%
In other words, the current directory and up to the next two above it in the path.
In ksh93 or bash, the substitution of $HOME
by ~
is easy, as is extracting the name of just the current directory, but I have yet to find a way of replicating the %c3
behaviour of tcsh. At present in ksh93 I have:
[ajcarr@Woehler] hello $
and
[ajcarr@Woehler] ~ $
Does anyone have any suggestions about how to do this?
bash ksh prompt tcsh
In tcsh, I have the default:
prompt [%m:%c3] %n%#
which gives prompts like:
[woehler:hacking/c/hello] ajcarr%
and
[woehler:~] ajcarr%
In other words, the current directory and up to the next two above it in the path.
In ksh93 or bash, the substitution of $HOME
by ~
is easy, as is extracting the name of just the current directory, but I have yet to find a way of replicating the %c3
behaviour of tcsh. At present in ksh93 I have:
[ajcarr@Woehler] hello $
and
[ajcarr@Woehler] ~ $
Does anyone have any suggestions about how to do this?
bash ksh prompt tcsh
bash ksh prompt tcsh
edited 2 hours ago
steeldriver
38.1k45489
38.1k45489
asked 2 hours ago
Alun CarrAlun Carr
6612
6612
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
For bash, you could achieve similar results by setting the PROMPT_DIRTRIM
variable:
$ PS1='[u@h] w$ '
[schaller@r2d2] ~$ pwd
/home/schaller
[schaller@r2d2] ~$ PROMPT_DIRTRIM=3
[schaller@r2d2] ~$ cd /home/schaller/tmp/513924/another/directory/here
[schaller@r2d2] ~/.../another/directory/here$
add a comment |
In ksh93
:
PS1='${PWD#${PWD%?/*/*/*}?/} $ '
share/doc/libnl-3-dev $ _
PS1='[${HOSTNAME%%.*}:${PWD#${PWD%?/*/*/*}?/}] $USER% '
[host:share/doc/libnl-3-dev] user% _
If you want it to also replace $HOME
with ~
, something nastier[1] is needed:
PS1='$(d=${PWD/#$HOME/"~"};printf %s "${d#${d%?/*/*/*}?/}") $ '
~/w/maemo $ cd sb2-pathmaps
w/maemo/sb2-pathmaps $ _
This should also work in bash
, though bash
has its own prompt escapes (eg. h
for ${HOSTNAME%%.*}
) and path shortening mechanism (with PROMPT_DIRTRIM
).
zsh
has prompt escapes quite similar but not identical to tcsh
:
zsh$ PS1='[%m:%3c] %n%# '
[host:share/doc/libnl-3-dev] user% _
[1] there may be some consolation in the fact that ksh93
doesn't fork()
another process for subshells which contain only builtins, like that $( ...; printf ...)
;-)
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513924%2fhow-to-produce-a-ps1-prompt-in-bash-or-ksh93-similar-to-tcsh%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
For bash, you could achieve similar results by setting the PROMPT_DIRTRIM
variable:
$ PS1='[u@h] w$ '
[schaller@r2d2] ~$ pwd
/home/schaller
[schaller@r2d2] ~$ PROMPT_DIRTRIM=3
[schaller@r2d2] ~$ cd /home/schaller/tmp/513924/another/directory/here
[schaller@r2d2] ~/.../another/directory/here$
add a comment |
For bash, you could achieve similar results by setting the PROMPT_DIRTRIM
variable:
$ PS1='[u@h] w$ '
[schaller@r2d2] ~$ pwd
/home/schaller
[schaller@r2d2] ~$ PROMPT_DIRTRIM=3
[schaller@r2d2] ~$ cd /home/schaller/tmp/513924/another/directory/here
[schaller@r2d2] ~/.../another/directory/here$
add a comment |
For bash, you could achieve similar results by setting the PROMPT_DIRTRIM
variable:
$ PS1='[u@h] w$ '
[schaller@r2d2] ~$ pwd
/home/schaller
[schaller@r2d2] ~$ PROMPT_DIRTRIM=3
[schaller@r2d2] ~$ cd /home/schaller/tmp/513924/another/directory/here
[schaller@r2d2] ~/.../another/directory/here$
For bash, you could achieve similar results by setting the PROMPT_DIRTRIM
variable:
$ PS1='[u@h] w$ '
[schaller@r2d2] ~$ pwd
/home/schaller
[schaller@r2d2] ~$ PROMPT_DIRTRIM=3
[schaller@r2d2] ~$ cd /home/schaller/tmp/513924/another/directory/here
[schaller@r2d2] ~/.../another/directory/here$
answered 1 hour ago
Jeff Schaller♦Jeff Schaller
45.2k1164147
45.2k1164147
add a comment |
add a comment |
In ksh93
:
PS1='${PWD#${PWD%?/*/*/*}?/} $ '
share/doc/libnl-3-dev $ _
PS1='[${HOSTNAME%%.*}:${PWD#${PWD%?/*/*/*}?/}] $USER% '
[host:share/doc/libnl-3-dev] user% _
If you want it to also replace $HOME
with ~
, something nastier[1] is needed:
PS1='$(d=${PWD/#$HOME/"~"};printf %s "${d#${d%?/*/*/*}?/}") $ '
~/w/maemo $ cd sb2-pathmaps
w/maemo/sb2-pathmaps $ _
This should also work in bash
, though bash
has its own prompt escapes (eg. h
for ${HOSTNAME%%.*}
) and path shortening mechanism (with PROMPT_DIRTRIM
).
zsh
has prompt escapes quite similar but not identical to tcsh
:
zsh$ PS1='[%m:%3c] %n%# '
[host:share/doc/libnl-3-dev] user% _
[1] there may be some consolation in the fact that ksh93
doesn't fork()
another process for subshells which contain only builtins, like that $( ...; printf ...)
;-)
add a comment |
In ksh93
:
PS1='${PWD#${PWD%?/*/*/*}?/} $ '
share/doc/libnl-3-dev $ _
PS1='[${HOSTNAME%%.*}:${PWD#${PWD%?/*/*/*}?/}] $USER% '
[host:share/doc/libnl-3-dev] user% _
If you want it to also replace $HOME
with ~
, something nastier[1] is needed:
PS1='$(d=${PWD/#$HOME/"~"};printf %s "${d#${d%?/*/*/*}?/}") $ '
~/w/maemo $ cd sb2-pathmaps
w/maemo/sb2-pathmaps $ _
This should also work in bash
, though bash
has its own prompt escapes (eg. h
for ${HOSTNAME%%.*}
) and path shortening mechanism (with PROMPT_DIRTRIM
).
zsh
has prompt escapes quite similar but not identical to tcsh
:
zsh$ PS1='[%m:%3c] %n%# '
[host:share/doc/libnl-3-dev] user% _
[1] there may be some consolation in the fact that ksh93
doesn't fork()
another process for subshells which contain only builtins, like that $( ...; printf ...)
;-)
add a comment |
In ksh93
:
PS1='${PWD#${PWD%?/*/*/*}?/} $ '
share/doc/libnl-3-dev $ _
PS1='[${HOSTNAME%%.*}:${PWD#${PWD%?/*/*/*}?/}] $USER% '
[host:share/doc/libnl-3-dev] user% _
If you want it to also replace $HOME
with ~
, something nastier[1] is needed:
PS1='$(d=${PWD/#$HOME/"~"};printf %s "${d#${d%?/*/*/*}?/}") $ '
~/w/maemo $ cd sb2-pathmaps
w/maemo/sb2-pathmaps $ _
This should also work in bash
, though bash
has its own prompt escapes (eg. h
for ${HOSTNAME%%.*}
) and path shortening mechanism (with PROMPT_DIRTRIM
).
zsh
has prompt escapes quite similar but not identical to tcsh
:
zsh$ PS1='[%m:%3c] %n%# '
[host:share/doc/libnl-3-dev] user% _
[1] there may be some consolation in the fact that ksh93
doesn't fork()
another process for subshells which contain only builtins, like that $( ...; printf ...)
;-)
In ksh93
:
PS1='${PWD#${PWD%?/*/*/*}?/} $ '
share/doc/libnl-3-dev $ _
PS1='[${HOSTNAME%%.*}:${PWD#${PWD%?/*/*/*}?/}] $USER% '
[host:share/doc/libnl-3-dev] user% _
If you want it to also replace $HOME
with ~
, something nastier[1] is needed:
PS1='$(d=${PWD/#$HOME/"~"};printf %s "${d#${d%?/*/*/*}?/}") $ '
~/w/maemo $ cd sb2-pathmaps
w/maemo/sb2-pathmaps $ _
This should also work in bash
, though bash
has its own prompt escapes (eg. h
for ${HOSTNAME%%.*}
) and path shortening mechanism (with PROMPT_DIRTRIM
).
zsh
has prompt escapes quite similar but not identical to tcsh
:
zsh$ PS1='[%m:%3c] %n%# '
[host:share/doc/libnl-3-dev] user% _
[1] there may be some consolation in the fact that ksh93
doesn't fork()
another process for subshells which contain only builtins, like that $( ...; printf ...)
;-)
edited 12 mins ago
answered 1 hour ago
mosvymosvy
10.6k11338
10.6k11338
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513924%2fhow-to-produce-a-ps1-prompt-in-bash-or-ksh93-similar-to-tcsh%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown