Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Or your usual **`dfu`** alias if it wraps the same steps.

## Layout notes

- **Fish** (`dot_config/fish/`): `conf.d/` snippets (PATH from **`00-chezmoi-path.fish.tmpl`**, env, abbreviations, dircolors, Catppuccin theme, vi bindings, secrets) and **`functions/`** for `dfu`, `load_secret`, `cdgr`, `up`, helpers, plus **`fish_prompt`** / **`fish_right_prompt`** (cwd + `USER at <~/.name>` + `fish_git_prompt`). Not ported from zsh: async right-prompt, `tog` / `vshow` / `vmultiline`.
- **Fish** (`dot_config/fish/`): `conf.d/` snippets (PATH from **`00-path.fish.tmpl`**, env, abbreviations, Catppuccin theme, vi bindings, secrets) and **`functions/`** for `dfu`, `load_secret`, `mcd`, `peek`, `up`, plus **`fish_prompt`** / **`fish_right_prompt`** (cwd + `USER at <~/.name>` + `fish_git_prompt`). Not ported from zsh: async right-prompt, `tog` / `vshow` / `vmultiline`.
- **Vim externals** ([`.chezmoiexternal.toml`](.chezmoiexternal.toml)): [vim-polyglot](https://github.com/sheerun/vim-polyglot) for bundled syntax; [vim-go](https://github.com/fatih/vim-go) with **`g:polyglot_disabled = ['go']`** in `dot_vimrc` so Go stays on vim-go. Separate trees for [preservim/nerdtree](https://github.com/preservim/nerdtree), [lightline.vim](https://github.com/itchyny/lightline.vim), [material.vim](https://github.com/kaicataldo/material.vim), [incsearch.vim](https://github.com/haya14busa/incsearch.vim). Dircolors: [nordtheme/dircolors](https://github.com/nordtheme/dircolors) under `~/.shell/plugins/nord-dircolors/`.
- **`dot_zshrc.tmpl`**: main zsh init (PATH, Homebrew on macOS, shared `~/.shell` and `~/.zsh` bits). Optional **`~/.zshrc.local`** is sourced last for machine-only overrides (not in this repo).
- **`dot_hammerspoon/`** is skipped on non-macOS via **`.chezmoiignore.tmpl`**.
Expand Down
7 changes: 7 additions & 0 deletions dot_config/fish/functions/_machine_name.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function _machine_name
if test -f $HOME/.name
cat $HOME/.name
else
hostname -s
end
Comment on lines +2 to +6

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Spawning external processes like cat and hostname on every prompt render introduces unnecessary latency and slows down terminal responsiveness. We can optimize this by using the built-in read command to read the file without forking, using the built-in prompt_hostname function, and caching the resolved machine name in a global variable so it is only computed once per session.

    if not set -q __machine_name_cache
        if test -f $HOME/.name
            read -l name < $HOME/.name
            set -g __machine_name_cache (string trim $name)
        else
            set -g __machine_name_cache (prompt_hostname)
        end
    end
    echo -n $__machine_name_cache

end
15 changes: 15 additions & 0 deletions dot_config/fish/functions/fish_prompt.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function fish_prompt
set -l cmd_status $status

echo -n (set_color green)(prompt_pwd)(set_color normal)' '

if test $cmd_status -ne 0
echo -n (set_color red)'!'(set_color normal)' '
end

if test (id -u) -eq 0
echo -n (set_color red)'>'(set_color normal)' '
else
echo -n (set_color magenta)'>'(set_color normal)' '
end
Comment on lines +10 to +14

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using (id -u) spawns an external process on every single prompt render, which can degrade shell performance. Fish provides a built-in function fish_is_root_user that checks user privileges extremely quickly without spawning any external processes.

    if fish_is_root_user
        echo -n (set_color red)'>'(set_color normal)' '
    else
        echo -n (set_color magenta)'>'(set_color normal)' '
    end

end
12 changes: 12 additions & 0 deletions dot_config/fish/functions/fish_right_prompt.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function fish_right_prompt
if test (id -u) -eq 0
echo -n (set_color red)(whoami)(set_color normal)
else
echo -n (set_color magenta)(whoami)(set_color normal)
end
Comment on lines +2 to +6

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Spawning external processes like (id -u) and (whoami) on every right prompt render degrades terminal responsiveness. We can optimize this by using the built-in fish_is_root_user function and the standard $USER environment variable, avoiding external process forks entirely.

    if fish_is_root_user
        echo -n (set_color red)"$USER"(set_color normal)
    else
        echo -n (set_color magenta)"$USER"(set_color normal)
    end


echo -n (set_color blue)' at '(set_color normal)
echo -n (set_color cyan)(_machine_name)(set_color normal)' '

fish_git_prompt
end