Just as a follow-up to my question about a newline in the prompt, I ended up
settling on these lines in my config.fish file in order to get the prompt set
just the way I want, including the newline before each prompt. The default
path-shortening behavior in the prompt drives me absolutely crazy and I hate
it, so it's overridden.
The resulting prompt includes the 24-hour time in HH:MM:SS and a bash-like $
for non-root users, and looks like this:
[15:13:59] user@hostname:~/.config/fish $
or
[15:13:59] root@hostname:~/.config/fish #
config.fish:
function just_the_time --description 'Shows just the time in 24-hour format'
date +"%T"
end
function prompt_pwd --description 'Overwrite unwanted path shortening behavior'
if test "$PWD" != "$HOME"
printf "%s" (echo $PWD|sed -e "s|^$HOME|~|")
else
echo '~'
end
end
function fish_prompt --description 'Write out the prompt'
# Just calculate these once, to save a few cycles when displaying the prompt
if not set -q __fish_prompt_hostname
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
end
if not set -q __fish_prompt_normal
set -g __fish_prompt_normal (set_color normal)
end
if not set -q __fish_color_clock
set -g __fish_color_clock (set_color black --bold)
end
if not set -q __fish_color_userandhost
set -g __fish_color_userandhost (set_color purple --bold)
end
if not set -q __fish_color_directories
set -g __fish_color_directories (set_color blue --bold)
switch $USER
case root
if not set -q __fish_prompt_cwd
if set -q fish_color_cwd_root
set -g __fish_prompt_cwd (set_color $fish_color_cwd_root)
else
set -g __fish_prompt_cwd (set_color $fish_color_cwd)
end
end
echo
echo -n -s "$__fish_color_clock" '[' (just_the_time) ']' ' '
"$__fish_color_userandhost" "$USER" @ "$__fish_prompt_hostname"
"$__fish_prompt_normal" ':' "$__fish_color_directories" (prompt_pwd)
"$__fish_prompt_normal" ' # '
case '*'
if not set -q __fish_prompt_cwd
set -g __fish_prompt_cwd (set_color $fish_color_cwd)
end
echo
echo -n -s "$__fish_color_clock" '[' (just_the_time) ']' ' '
"$__fish_color_userandhost" "$USER" @ "$__fish_prompt_hostname"
"$__fish_prompt_normal" ':' "$__fish_color_directories" (prompt_pwd)
"$__fish_prompt_normal" ' $ '
end
end
On Wednesday, June 13, 2012 at 8:59 AM, David Frascone wrote:
> When I type funced fish_prompt, and press the up arrow, my fish exits. If I
> use the left arrow, and scroll a lot, this works.
>
> Strangely enough, this does *not* happen if I run a new fish (i.e. $ fish)
> then do the funced.
>
> Maybe login shells can't edit the prompt?
>
> -Dave
>
> On Wed, Jun 13, 2012 at 12:13 AM, Elis Axelsson <[email protected]
> (mailto:[email protected])> wrote:
> > On 13 June 2012 04:34, Lee <[email protected]
> > (mailto:[email protected])> wrote:
> > > Just found the fishfish shell, and I'm excited about using it for my OS X
> > > and Linux boxes. However, I'm having trouble modifying the shell prompt to
> > > start with a newline. I've become accustomed to having each prompt
> > > prefaced
> > > by a blank line, in order to break up the constant visual flow of the
> > > terminal window. In bash, I just start $PS1 with a \n, but damned if I can
> > > figure out how to accomplish this in fishfish. Some searching reveals that
> > > others have had this issue in the past, but I'm unable to find if anyone
> > > worked out the solution.
> > >
> > > I know it seems nit-picky, but it's enough to keep me in bash unless I can
> > > figure it out. Anyone have any advice or suggestions?
> >
> > If you do, funced fish_prompt to get the editor open with the
> > function. And add "echo" before the printf at the end of that
> > function, it will print a newline for you. And echo is builtin so it's
> > fast. And you can use funcsave to save your edits :)
> >
> > --
> > Elis "etu" Axelsson
> >
> > ------------------------------------------------------------------------------
> > Live Security Virtual Conference
> > Exclusive live event will cover all the ways today's security and
> > threat landscape has changed and how IT managers can respond. Discussions
> > will include endpoint security, mobile security and the latest in malware
> > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> > _______________________________________________
> > Fish-users mailing list
> > [email protected] (mailto:[email protected])
> > https://lists.sourceforge.net/lists/listinfo/fish-users
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users