Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 205809

Summary: app-shells/fish - patch to allow newlines in fish prompt
Product: Gentoo Linux Reporter: Denilson Sá Maia <denilsonsa>
Component: Current packagesAssignee: No maintainer - Look at https://wiki.gentoo.org/wiki/Project:Proxy_Maintainers if you want to take care of it <maintainer-needed>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
URL: http://fishshell.org/
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: Patch to allow newlines (\n) in fish prompt

Description Denilson Sá Maia 2008-01-14 15:38:28 UTC
Here is my suggestion of fish_prompt function to print a colorful gentoo-ish prompt (so fish can look like bash). I've just edited the function already available at /usr/share/fish/functions/fish_prompt.fish and copied that to my ~/.config/fish/config.fish. I've tested with app-shells/fish-1.22.1


# Colorful gentoo-ish fish prompt:
function fish_prompt -d (N_ "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 test (id -u) = 0
		printf '%s%s %s%s%s> ' (set_color -o red) $__fish_prompt_hostname (set_color -o blue) (prompt_pwd) "$__fish_prompt_normal"
	else
		printf '%s%s@%s %s%s%s> ' (set_color -o green) $USER $__fish_prompt_hostname (set_color -o blue) (prompt_pwd) "$__fish_prompt_normal"
	end
end


Some comments:
1. I use (id -u) instead of $USER because I want to know the effective UID ($EUID, in bash). It may happen that the current EUID is zero (root), but the UID is from another user. Since I don't know if fish has any $EUID-like variable, I'm running (id -u). If you know a better way of doing this, please, update this code.
2. I'm calling (set_color) multiple times. Probably I shouldn't, and I should store them at global vars (like $__fish_prompt_normal). Please, feel free to improve this.


I don't know if gentoo guys think it is a good idea to change the default prompt colors for fish (even though you do it for bash). Anyway, I just wanted to share this function to other people, and make the job easier for gentoo devs if someday they want to do such customization on gentoo's fish.
Comment 1 Donnie Berkholz (RETIRED) gentoo-dev 2008-01-14 22:31:54 UTC
This sounds like a good idea. Could you test it out with 1.23.0? I haven't tried your prompt, does it exactly mirror the bash one?
Comment 2 Denilson Sá Maia 2008-01-15 03:50:43 UTC
It mirror(In reply to comment #1)
> This sounds like a good idea. Could you test it out with 1.23.0? I haven't
> tried your prompt, does it exactly mirror the bash one?

It mirrors gentoo-bash colors, but it keeps " >" at the end. (while bash uses " $" or " #" at the end)

I haven't installed 1.23.0 yet.

BTW, that code I submitted can have some improvements (I have some in my mind, I might code these improvements soon).

I'm not sure, but I think that gentoo should add a file at /etc/fish/functions/fish_prompt.fish, instead of patching the original /usr/share/fish/functions/fish_prompt.fish. I've tested neither of them, yet. What do you think?
Comment 3 Donnie Berkholz (RETIRED) gentoo-dev 2008-01-15 04:10:54 UTC
/etc is for user changes; a distro change should still go into /usr.
Comment 4 Denilson Sá Maia 2008-01-15 04:17:46 UTC
(In reply to comment #3)
> /etc is for user changes; a distro change should still go into /usr.

Why, then, such change in bash was done in /etc/bash/bashrc? Lack of /usr/ files for bash?

IMHO, the advantage about making this change in /etc/ is to leave the original unmodified version at /usr, so the user may be able to read the original. (ok, ok, the user may also get the tarball and uncompress it)
Comment 5 Donnie Berkholz (RETIRED) gentoo-dev 2008-01-15 08:00:27 UTC
bash has no system defaults in /usr like fish does. hal might be a better comparison -- it installs some fdi files to /usr and system overrides of them go in /etc.
Comment 6 James Bowlin 2010-11-22 10:34:07 UTC
Created attachment 255097 [details, diff]
Patch to allow newlines (\n) in fish prompt

I found the patch here:
http://benhoskin.gs/2009/11/25/multi-line-prompts-in-fish/

I applied it on my system and it worked like a champ.  I hope this was the right
place for me to submit the patch.  I could start a new bug if you want me to.
Comment 7 Michael Weber (RETIRED) gentoo-dev 2011-11-12 12:14:13 UTC
+  12 Nov 2011; Michael Weber <xmw@gentoo.org> +fish-1.23.1-r2.ebuild,
+  +files/fish-1.23.1-multi-line_prompts.patch:
+  Revbump to optionally include multi-line prompt patch by Ben Hoskings as
+  suggested by James Bowlin (bug 205809)
+
Comment 8 Denilson Sá Maia 2011-11-13 01:51:18 UTC
I believe there was some confusion here. This bug (that is an "enhancement") was about adding a colorful Gentoo prompt, similar to the bash prompt. Then James Bowlin posted an unrelated patch here, which was accepted and then this bug was closed, even though the summary of the bug was not "fixed".

I'm changing the summary to reflect the accepted patch.