Skip to content

Commit 0e33a92

Browse files
committed
Refine fish navigation and prompt UX
1 parent b087d99 commit 0e33a92

File tree

5 files changed

+187
-12
lines changed

5 files changed

+187
-12
lines changed

dot_config/fish/conf.d/50-functions.fish.tmpl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,23 @@ function __braden_fzf_history
312312
return
313313
end
314314

315-
set -l selection (history --max=2000 | fzf \
315+
set -l history_delim (printf '\t')
316+
set -l selection (history search --show-time="%s$history_delim" --max=2000 | fzf \
316317
--scheme=history \
317318
--no-sort \
318-
--preview 'echo {} | bat --color=always --language=fish --style=plain --theme="Catppuccin Macchiato"' \
319+
--delimiter="$history_delim" \
320+
--with-nth=2.. \
321+
--preview='__braden_fzf_history_preview {1} {2..}' \
319322
--preview-window=right:60%:wrap:border-left \
320323
--query=(commandline))
321324

322325
if test -n "$selection"
323-
commandline --replace -- $selection
326+
set -l selection_fields (string split -m1 $history_delim -- $selection)
327+
if test (count $selection_fields) -ge 2
328+
commandline --replace -- $selection_fields[2]
329+
else
330+
commandline --replace -- $selection
331+
end
324332
end
325333

326334
commandline -f repaint

dot_config/fish/conf.d/70-keybindings.fish

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,80 @@ function __braden_down_or_history
1818
end
1919
end
2020

21+
function __braden_select_with_motion --argument-names motion
22+
# Reusing begin-selection resets the anchor, so only start it once.
23+
set -l selection (commandline -s)
24+
if test (count $selection) -eq 0
25+
commandline -f begin-selection
26+
end
27+
28+
commandline -f $motion repaint
29+
end
30+
31+
function __braden_move_or_collapse_selection --argument-names edge motion
32+
set -l selection_start (commandline -B)
33+
set -l selection_end (commandline -E)
34+
35+
if test "$selection_start" != "$selection_end"
36+
switch $edge
37+
case start
38+
commandline -C $selection_start
39+
case end
40+
commandline -C $selection_end
41+
end
42+
43+
commandline -f end-selection repaint
44+
return
45+
end
46+
47+
commandline -f $motion repaint
48+
end
49+
50+
function __braden_up_or_history_or_collapse_selection
51+
set -l selection_start (commandline -B)
52+
set -l selection_end (commandline -E)
53+
54+
if test "$selection_start" != "$selection_end"
55+
__braden_move_or_collapse_selection start up-line
56+
else
57+
__braden_up_or_history
58+
end
59+
end
60+
61+
function __braden_down_or_history_or_collapse_selection
62+
set -l selection_start (commandline -B)
63+
set -l selection_end (commandline -E)
64+
65+
if test "$selection_start" != "$selection_end"
66+
__braden_move_or_collapse_selection end down-line
67+
else
68+
__braden_down_or_history
69+
end
70+
end
71+
2172
if status is-interactive
2273
bind \r __braden_magic_enter
2374
bind \e\e __braden_toggle_sudo
2475
bind \cy yazi_choose
25-
bind up __braden_up_or_history
26-
bind down __braden_down_or_history
27-
bind \e\[A __braden_up_or_history
28-
bind \e\[B __braden_down_or_history
76+
bind super-c fish_clipboard_copy
77+
bind left '__braden_move_or_collapse_selection start backward-char'
78+
bind right '__braden_move_or_collapse_selection end forward-char'
79+
bind home '__braden_move_or_collapse_selection start beginning-of-line'
80+
bind end '__braden_move_or_collapse_selection end end-of-line'
81+
bind alt-left '__braden_move_or_collapse_selection start prevd-or-backward-word'
82+
bind alt-right '__braden_move_or_collapse_selection end nextd-or-forward-word'
83+
bind ctrl-a '__braden_move_or_collapse_selection start beginning-of-line'
84+
bind ctrl-e '__braden_move_or_collapse_selection end end-of-line'
85+
bind up __braden_up_or_history_or_collapse_selection
86+
bind down __braden_down_or_history_or_collapse_selection
87+
bind \e\[A __braden_up_or_history_or_collapse_selection
88+
bind \e\[B __braden_down_or_history_or_collapse_selection
89+
bind shift-left '__braden_select_with_motion backward-char'
90+
bind shift-right '__braden_select_with_motion forward-char'
91+
bind shift-up '__braden_select_with_motion up-line'
92+
bind shift-down '__braden_select_with_motion down-line'
93+
bind shift-home '__braden_select_with_motion beginning-of-line'
94+
bind shift-end '__braden_select_with_motion end-of-line'
95+
bind alt-shift-left '__braden_select_with_motion backward-word'
96+
bind alt-shift-right '__braden_select_with_motion forward-word'
2997
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# =============================================================================
2+
# Prompt State
3+
# =============================================================================
4+
5+
function __braden_find_git_root
6+
set -l dir $PWD
7+
8+
while true
9+
if test -e "$dir/.git"
10+
echo $dir
11+
return 0
12+
end
13+
14+
if test "$dir" = "/"
15+
return 1
16+
end
17+
18+
set dir (path dirname $dir)
19+
end
20+
end
21+
22+
function __braden_set_starship_git_dirty
23+
set -e -g BRADEN_GIT_DIRTY
24+
25+
set -l git_root (__braden_find_git_root)
26+
or return
27+
28+
command git -C "$git_root" diff-index --quiet HEAD -- ^/dev/null
29+
or begin
30+
set -gx BRADEN_GIT_DIRTY "*"
31+
return
32+
end
33+
34+
set -l untracked (command git -C "$git_root" ls-files --others --exclude-standard --directory --no-empty-directory | head -n 1)
35+
if test -n "$untracked"
36+
set -gx BRADEN_GIT_DIRTY "*"
37+
end
38+
end
39+
40+
if status is-interactive
41+
if functions -q fish_prompt; and not functions -q __braden_starship_fish_prompt
42+
functions -c fish_prompt __braden_starship_fish_prompt
43+
44+
function fish_prompt
45+
if not contains -- --final-rendering $argv
46+
__braden_set_starship_git_dirty
47+
end
48+
49+
__braden_starship_fish_prompt $argv
50+
end
51+
end
52+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function __braden_fzf_history_preview --argument-names timestamp command
2+
set -l absolute_time
3+
if date -r $timestamp '+%Y-%m-%d %H:%M:%S %Z' >/dev/null 2>/dev/null
4+
set absolute_time (date -r $timestamp '+%Y-%m-%d %H:%M:%S %Z')
5+
else
6+
set absolute_time (date -d "@$timestamp" '+%Y-%m-%d %H:%M:%S %Z' 2>/dev/null)
7+
end
8+
9+
set -l now (date +%s)
10+
set -l delta (math "max(0, $now - $timestamp)")
11+
set -l age
12+
13+
if test $delta -lt 60
14+
set age "$delta"s ago
15+
else if test $delta -lt 3600
16+
set age (math --scale=0 "$delta / 60")"m ago"
17+
else if test $delta -lt 86400
18+
set age (math --scale=0 "$delta / 3600")"h ago"
19+
else if test $delta -lt 604800
20+
set age (math --scale=0 "$delta / 86400")"d ago"
21+
else if test $delta -lt 2592000
22+
set age (math --scale=0 "$delta / 604800")"w ago"
23+
else if test $delta -lt 31536000
24+
set age (math --scale=0 "$delta / 2592000")"mo ago"
25+
else
26+
set age (math --scale=0 "$delta / 31536000")"y ago"
27+
end
28+
29+
printf 'Ran: %s\nAgo: %s\n\n' "$absolute_time" "$age"
30+
31+
if command -q bat
32+
printf '%s\n' "$command" | bat \
33+
--color=always \
34+
--language=fish \
35+
--style=plain \
36+
--theme='Catppuccin Macchiato'
37+
else
38+
printf '%s\n' "$command"
39+
end
40+
end

dot_config/starship.toml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ continuation_prompt = "[▸▹ ](overlay1)"
1414

1515
# Left side: context + character (where you type)
1616
# Dimmed diamond separator between directory and git
17-
format = """$username$hostname$container$directory$git_branch$git_state $character"""
17+
format = """$username$hostname$container$directory$git_branch${env_var.BRADEN_GIT_DIRTY}$git_state$character"""
1818

1919
# Right side: metadata only (startup/duration/time)
2020
right_format = """${env_var.ZSH_STARTUP_MS}$cmd_duration$time"""
@@ -56,14 +56,16 @@ before_repo_root_style = "dimmed sapphire"
5656
# Git Modules
5757
# =============================================================================
5858
[git_branch]
59-
format = "[⋄](overlay0)[$symbol$branch]($style)"
59+
format = "[$symbol$branch]($style)"
6060
symbol = "󰘬"
6161
style = "mauve"
6262

6363
[git_status]
6464
disabled = true
65-
format = '([$all_status$ahead_behind]($style))'
66-
style = "flamingo"
65+
ignore_submodules = true
66+
use_git_executable = false
67+
format = '[ $all_status$ahead_behind]($style)'
68+
style = "overlay1"
6769
conflicted = "󰞇 "
6870
ahead = "󰜷${count}"
6971
behind = "󰜮${count}"
@@ -82,7 +84,7 @@ tag_symbol = " 󰓹 "
8284
style = "mauve"
8385

8486
[git_state]
85-
format = '[\($state( $progress_current of $progress_total)\)]($style) '
87+
format = '[\($state( $progress_current of $progress_total)\)]($style)'
8688
cherry_pick = "[󰇚 PICKING](bold red)"
8789
rebase = "[󰳖 REBASING](bold mauve)"
8890
merge = "[󰘭 MERGING](bold blue)"
@@ -329,6 +331,11 @@ variable = "ZSH_STARTUP_MS"
329331
format = "[󱎫 ${env_value}ms]($style) "
330332
style = "overlay1"
331333

334+
[env_var.BRADEN_GIT_DIRTY]
335+
variable = "BRADEN_GIT_DIRTY"
336+
format = "[$env_value]($style)"
337+
style = "peach"
338+
332339
# =============================================================================
333340
# Color Palette (must be at the end of the file)
334341
# =============================================================================

0 commit comments

Comments
 (0)