-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Prompt changes to ">" when fish thinks it's too long #904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This happens deliberately if the prompt is too wide to fit on the screen. Is that what's going on here? |
I assume so. The width of shell is 50. The prompt would take 24 characters (if I read it correctly), but it could take way more if Except that doesn't make sense. If the prompt has 35 characters, why it would be too long? I've tried using the prompt he used myself, but I don't see anything wrong. |
Is there a way (or example prompts) to handle this in a "responsive" way, e.g. don't display machine info if the prompt is too wide or shorten the directory path to the most significant part? |
@rgieseke: Sure, check |
This has been an issue for me, too. Personally, I'd rather it wrap my prompt or truncate it or give me the option to override this default prompt. The ">" is really rough for me, I have an emotional dependency on a coloured prompt, and possibly also on seeing the cwd. Without that, I feel lost. |
That bothers me, too. I've asked in mail list, no sequential follow-ups though. I looked up the commit history and found the comment in screen.cpp
I propose that if an env var set (like FISH_WRAP_LONG_LINE), then we skip those lines in screen.cpp to make the prompt "> ". Something like this. env_var_t wrap = env_get_string(L"FISH_WRAP_LONG_LINE");
if (wrap.missing())
{
if (left_prompt_layout.max_line_width >= screen_width)
{
/* If we have a multi-line prompt, see if the longest line fits; if not neuter the whole left prompt */
left_prompt = L"> ";
left_prompt_width = 2;
}
}
if (left_prompt_width + right_prompt_width >= screen_width)
{
/* Nix right_prompt */
right_prompt = L"";
right_prompt_width = 0;
}
if (wrap.missing())
{
if (left_prompt_width + right_prompt_width >= screen_width)
{
/* Still doesn't fit, neuter left_prompt */
left_prompt = L"> ";
left_prompt_width = 2;
}
} |
|
@glitchmr I read the design document, but I don't know what the alternative way is. Actually, by greping the source code, there are some configurations, including FISHD_SOCKET_DIR, TERM, fish_term256, fish_function_path, FISH_CLIPBOARD_CMD, etc... it's not the whole, but here is the idea. As the comment I pasted there said, the difficulty is about the escape sequence. I've no experience about that, but I assume long-line wrap is more regular than that. (Or it's quite common just I don't know what it is? Could anyone give an example of that which will cause the problem� wrapping) I myself don't like to use another variable, either. I'll be more than happy to have a better solution to satisfy both. |
On the mailing list, Peter suggests defining a new fish_short_prompt function. Wrapping the prompt is a possibility; truncating it is where we run into problems with control characters. (e.g. consider truncating a prompt which sets the proxy icon in OS X ala #68). We would all like to avoid magic variables and new functions ( I also think that wrapping lacks elegance, and has the potential to produce pathological scenarios. Consider the case where a user accidentally includes It would be great if we had an example of how to inspect |
@zanchey I don't get it that why By wrapping I mean fish does nothing, leaving it to the terminal, and as my trial to remove the two I'd like to know a case the wrapping doesn't work. (I'm using iTerm2 under Mac OS X, no idea if iTerm2 has anything special) Regarding the
Skip the escape sequences. Even though there will be a function to automatically do the job (The function will be easy to implement), it's still way too complicated for a simple concept. |
Most of the problems associated with wrapping revolve around cursor motion, window resizing, and fish_right_prompt. Wrapping the prompt is probably doable, it's just tricky. |
Truncating would still be more desirable than the arrow in the meanwhile. |
Truncating is actually harder because of control sequences. |
Was about to open an issue for this, glad I kept searching. |
Coming to the party late. Sorry. I ran into this issue the other day, and stupidly tried to figure out what was going on before I searched for it. After wasting a few hours, it finally dawned on me what was going on. Then I searched (facepalm). Anyway, I just updated my fish_prompt function to adjust the directory if the prompt is too long. So far, it looks promising. Like a lot of people, I put the branch name in the prompt if I'm in a Git repository. Unlike a lot of people, though, I use a two line prompt where prompt line 1 is all the information and prompt line 2 is the "command entry point", so to speak. In my situation, I have to put together the content of pl1 to see if it's too long, and then adjust the directory if necessary. It's kind of cumbersome, but it does work. # other stuff happens first, like setting some color variables and things that are irrelevant
# to this discussion.
...
# get the current dir nicely ... replace $HOME with "~"
set -l realhome ~
set -l dir (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD)
# start with the "full" directory
set -l pl1 "[$USER] $dir"
# try to get the current branch
set -l git_branch (git rev-parse --abbrev-ref HEAD 2> /dev/null)
if test "$git_branch" != ""
# we have a branch, so let's add that in
set pl1 "$pl1 ($git_branch)"
end
# get the length
set -l pl1_len (string length $pl1)
if test $pl1_len -gt $COLUMNS
# too long, use the shortened version of dir instead
set dir (prompt_pwd)
end
# we can now build common pieces of the prompt, but because we need to
# choose colors based on state, we have to reevaluate some things
set -l prompt_line_1 '\n%s[%s] %s%s%s'
set -l prompt_line_1_args "$user_color" $USER "$color_blue" "$dir" "$color_normal"
set -l prompt_line_2 '%s->%s '
set -l prompt_line_2_args "$shell_status_color" "$color_normal"
if test "$git_branch" != ""
# start by assuming the working dir is dirty
set -l git_status_color $color_red
git status | grep clean > /dev/null
if test $status -eq 0
# Oh, no changes, so let's use green for the git branch
set git_status_color $color_green
end
set -l git_prompt '%s(%s)%s'
set -l git_prompt_args "$git_status_color" "$git_branch" "$color_normal"
set prompt_line_1 "$prompt_line_1 $git_prompt"
set prompt_line_1_args $prompt_line_1_args $git_prompt_args
end
# All together now ...
set -l prompt_string "$prompt_line_1\n$prompt_line_2"
set -l prompt_args $prompt_line_1_args $prompt_line_2_args
printf $prompt_string $prompt_args I use tmux all day and have been using pane zooming (Prefix z). When zooming in and out, the prompt changes accordingly. I hope someone finds this useful or could recommend ways to make it better. |
I use a two line prompt as well. I believe, many people do. To get arround this issue I put the first line with all the interesting stuff in a function Edit: |
Adding some (hopefully useful) feedback to this. I also had "sometimes" the I understand the no-configuration philosophy, but I think here discoverability is one problem, and the other is "ignoring" my prompt by replacing it by another (rule of least surprise). So here's my idea:
Let me know what you think! |
@aramiscd, can you post some example code showing how you solved this? |
I'm inclined to agree with @christianrondeau that fish should definitely issue an explanatory message about why the output of |
In keeping with historical practice there's really only a couple of reasonable choices: > and $ |
By "historical practice" I'm talking about shells like the original Bourne shell. And if we're so desperate to display any sort of prompt that we're falling back to displaying a single character prompt it's hard to justify introducing colors and non-ASCII characters. |
@krader1961 my thinking was that a "one-character fall back prompt" is a "short prompt" (albeit a very short one). Right now I have to do some crazy string concatenation to check if the prompt does not fit: https://github.com/christianrondeau/dotfiles/blob/master/fish/.config/fish/functions/fish_prompt.fish#L42 - I'd like my prompt on my phone to still be "my" prompt, rather than I think having any way to fall back to anything (be it a short_prompt, single-character prompt config, or even better a built-in way to pass prompt components that support a long and short version, though that's out of the scope of that discussion I think) is the "useful" thing. The "important" thing is to at least know where that came from :) Since that seems to be an opinionated topic, and I now have a fallback, I'd suggest to "solve" this specific issue with a simple useful message, and all short prompt ideas could become issues on their own. I do believe however that if we include the useful message in the short prompt itself (e.g. |
I like the idea of only using the fallback when the actual prompt does not fit. One could check $COLUMNS in |
What about using the prompt's last nonwhitespace character for the single-character prompt? The likelihood is very high that it is what the user would choose. |
Truncating may be a problem, there may be escape sequences that start a format but the sequence that ends it may be truncated (so the format may continue in the following line). If you just wrap around, even if it doesn't look great, at least the prompt doesn't behave in a different way than when it is not truncated. |
@JoshCheek but why one character? I honestly don't know why removing all the information from the prompt is a good idea. I have a long prompt because I want that information. If I didn't care at all about it I would simply have a shorter prompt. And again, if that's what you want, you can edit the function to do it. |
Here's what I've done to dynamically make my prompt smaller based on It wasn't exactly straightforward, so I don't think customizing is that easy and there should be better support in fish for handling this I'm using a theme (cbjohnson) which uses a 2-line prompt, modify to suit your needs
I wasn't able to put the color-removing / prompt length calculation logic in a separate function. I think it's likely some issues with fish (I was stuck because of this, and even if I don't pipe stdin and rely on Also In case anyone finds a way to improve the above, please do share. |
I opened this one oh-my-fish/oh-my-fish#627 - I'm trying to do something similar I guess (control how it looks), first letter really isn't useful, I'd prefer only last directory |
@gkatsanos: Since fish 2.3.0, the |
znculee/fish-theme-xtli |
Any news here? I've lost my prompt and wondering what to do. Also I usually have the pwd shortening off, but would prefer it to this kind of shortening. How could I do that? Divide $COLUMNS by two and change the setting? |
@mixmastamyk You may want to try this theme znculee/fish-theme-xtli. |
Reimplement workaround for truncated strings (#49) using single function as currently recommended in fish-shell/fish-shell#904 (comment) instead of event handler. Update first line of the prompt when moving through directory history with "Alt + ←" and "Alt + →" (#66). Also resolve #62 and #67. Refactor code into smaller functions.
Inspired by @wwwjfy, I ended up adding the following code to my # shorten the prompt, but only when it's too long
set -g fish_prompt_pwd_dir_length 0
set -l longprompt $USER (prompt_hostname) (prompt_pwd) (__fish_vcs_prompt) $prompt_status
if test (expr length "$longprompt") -gt $COLUMNS
set -g fish_prompt_pwd_dir_length 1
end |
Unfortunately this didn't satisfy my requirements. That's why I have written a script that does line wrapping of the prompt, as well as trimming of too long directory names for me. If you're just here for the solution scroll to the bottom of this post. Why this is a problemImagine for example if you have a directory user@machine ~/very_long_directory_name_so_that_with_a_lower_columns_number_you_will_experience_the_described_behaviour/aab/dir
$ and a directory user@machine ~/very_long_directory_name_so_that_with_a_lower_columns_number_you_will_experience_the_described_behaviour/aax/dir
$ fish would abbreviate both directories to user@machine ~/v/a/dir
$ when using Imagine for example you have the following directories: user@machine ~
$ ls
aaab/ aaba/ az/ fish doesn't abbreviate This is just really unfortunate, because why should I bother to have a directory display in my prompt in the first place, if I have to manually issue How to solve this problemThats why I developed a script that automatically wraps directory strings that are too long (splitting the path at the In my case user@machine ~/very_long_directory_name_so_that_with_a_lower_columns_number_you_will_experience_the_described_behaviour/aax/dir
$ would become (with user@machine ~/
> very_long_directory_name_so_that_with_a_lower_colu[...]/
> aax/dir
$ Of course this solution isn't perfect, but it's sufficient for me at least. The solutionTo view the script, please consult my construct_column_aware_prompt.fish function for the function itself, as well as my fish_prompt.fish config on how to use said function. |
This comment has been minimized.
This comment has been minimized.
I took a run at truncation. The approach is that, for each line of the prompt whose width exceeds $COLUMNS, we prepend ellipsis and then start removing characters from the left until it fits, while skipping escape sequences. I chose the left because it probably has the least interesting information (e.g. parent directories). I personally prefer very minimalist prompts so probably this will need to be refined by someone who uses it. I think it's best to open new issues for any changes, as this one has been quite worked over. |
Fish 2.0.0. When I cd some directories, my prompt (robbyrussell + small changes) becomes stupid (it has nothing to do with git or with
$var
in cd, I checked).The text was updated successfully, but these errors were encountered: