oh-my-fish / theme-agnoster

MIT License
96 stars 64 forks source link

How to add date to beginning of prompt? #37

Closed seanr closed 4 years ago

seanr commented 5 years ago

I found this issue: https://github.com/oh-my-fish/theme-agnoster/issues/22 However, the links in the response don't seem to point to the right lines anymore, and there's also no detail provided on what actually needs to be added. I'm really just an end-user with no fish programming experience (I'm a PHP guy), but I really need a timestamp at the beginning of my prompts (I'm running a lot of repetitive migration commands right now and I can't tell when I ran what, which is very frustrating).

sn0cr commented 5 years ago

I guess you already know part of it but I write that here so people can find that here. 😉

So I'm guessing you already know that you need to modify / implement the function fish_right_prompt somewhere (for example in your config.fish in ~/.config/fish/config.fish if you do not use the visual vi mode)

Here's who to get the implementation in the screenshot below:

set -q color_right_time; or set color_right_time red
set -q color_right_time_indicator; or set color_right_time_indicator yellow
set left_segment_separator \uE0B2

function prompt_time -d 'prints the current time'
  set_color $color_right_time
  echo "$left_segment_separator"
  set_color -b $color_right_time $color_right_time_indicator
  date "+%H:%M:%S"
  set_color -b $color_right_time normal
  echo "$left_segment_separator"
end

function fish_right_prompt -d 'Prints right prompt'
  prompt_time
  set_color normal
end
screenshot 2018-12-06 at 12 44 47

If there are some more questions about that, feel free to ask them and goof luck with your migrations.

seanr commented 5 years ago

That file didn't exist for me (it's using agnoster's fish_prompt.fish via a symlink at ~/.config/fish/functions/fish_prompt.fish). I created it and opened a new iterm window and also tried restarting iterm altogether, but it had no effect.

seanr commented 5 years ago

Got it working by editing ~/.local/share/omf/themes/agnoster/fish_right_prompt.fish - I'm sure that's probably not the right way to do it since that would be overwritten in any updates, so any further advice you can offer would be helpful.

sn0cr commented 5 years ago

The file ~/.config/fish/config.fish should exist as it is the configuration file for fish. This file would be the best location. Otherwise, you could also put it in a file in ~/.config/fish/functions (link) (for example you could call it fish_prompt.fish).

— On a side note — Did I understand you correctly that you want to have a date on the right, or do you want to have it on the left side? I just assumed you wanted to have it on the right as you provided links to this discussion...