如何移除fish shell终端右侧时间戳并自定义该元素
Hey there! Let’s sort out your fish shell timestamp needs — first removing that right-side timestamp, then customizing it to match your desired style.
Fish shell’s right-side prompt is controlled by the fish_right_prompt function. Here’s how to ditch the timestamp:
- Open the function editor for the right prompt:
funced fish_right_prompt - Look for any lines that generate the timestamp — they’ll usually involve
dateor a pre-defined timestamp variable. Delete those lines entirely. - Save your changes to make them permanent:
funcsave fish_right_prompt - Either restart your terminal or run
source ~/.config/fish/config.fishto apply the changes immediately.
If you’re using a fish theme (like Oh My Fish’s bobthefish), check the theme’s configuration first — many themes have a toggle for the right prompt timestamp (e.g., set -g theme_show_right_prompt no for bobthefish).
Let’s build a custom timestamp that matches your desired look (we’ll use a common styled example, which you can tweak further):
- Reopen the right prompt editor:
funced fish_right_prompt - Replace the existing content (or add this if starting fresh) with code that defines your custom timestamp. For example, this creates a bracketed, gray-background white-text timestamp:
Quick breakdown:# Custom timestamp: gray background, white text, [HH:MM:SS] format echo -n (set_color -b brblack white) "["(date '+%H:%M:%S')"]"(set_color normal)set_color -b brblack white: Sets a soft gray background and white text for the timestampdate '+%H:%M:%S': Generates time in 24-hour format (adjust to'%I:%M %p'for 12-hour AM/PM, or'%Y-%m-%d %H:%M'to add the date)(set_color normal): Resets colors back to your terminal’s default after the timestamp
- Save the function:
funcsave fish_right_prompt - Test it out by running any command — your new styled timestamp should appear on the right side instantly!
Tweak the set_color arguments or date format string to match your exact desired style.
内容的提问来源于stack exchange,提问作者mickkk

