Skip to content

Commit

Permalink
Update fish settings (#108)
Browse files Browse the repository at this point in the history
* Update fish abbrevs.

* Reformat xkb shortcuts.

* Update Fish prompt.

* Fi Python venv prompt.

* Split up Fish config into smaller files.

* Re-write Fish functions in Nix.

* Use Nix store paths in Frish prompt functions.

* Use the built-in echo.

* Add right prompt.
  • Loading branch information
attilaolah authored Sep 27, 2024
1 parent f2b0821 commit 289b414
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 175 deletions.
98 changes: 0 additions & 98 deletions home-manager/.config/fish/functions/fish_prompt.fish

This file was deleted.

28 changes: 13 additions & 15 deletions home-manager/file.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
...
}: let
desktopAttrs = attrs: lib.attrsets.optionalAttrs desktop attrs;
foot-catppuccin-mocha = pkgs.stdenv.mkDerivation {
name = "foot-catppuccin-mocha";
# TODO: renovate
src = pkgs.fetchFromGitHub {
owner = "catppuccin";
repo = "foot";
rev = "ee5549af72ab78520ac2aa1c671bf5c2d347c8ca";
sha256 = "sha256-3hK9klXwdHhprG2wUMt7nBfbL1mb/gl+k/MtJUuY000=";
};
installPhase = ''
cp --recursive catppuccin-mocha.ini $out
'';
};
in {
home.file =
{
Expand All @@ -19,7 +32,6 @@ in {
Match host * exec "gpg-connect-agent UPDATESTARTUPTTY /bye"
'';
# TODO: Use xdg.configFile!
".config/fish/functions/fish_prompt.fish".source = ./.config/fish/functions/fish_prompt.fish;
".config/nvim/init.lua".source = ./.config/nvim/init.lua;
".config/nvim/lua/chadrc.lua".source = ./.config/nvim/lua/chadrc.lua;
".config/nvim/lua/configs/conform.lua".source = ./.config/nvim/lua/configs/conform.lua;
Expand All @@ -30,20 +42,6 @@ in {
".config/nvim/lua/plugins/init.lua".source = ./.config/nvim/lua/plugins/init.lua;
}
// desktopAttrs (let
foot-catppuccin-mocha = pkgs.stdenv.mkDerivation {
name = "foot-catppuccin-mocha";
# TODO: renovate
src = pkgs.fetchFromGitHub {
owner = "catppuccin";
repo = "foot";
rev = "ee5549af72ab78520ac2aa1c671bf5c2d347c8ca";
sha256 = "sha256-3hK9klXwdHhprG2wUMt7nBfbL1mb/gl+k/MtJUuY000=";
};
installPhase = ''
cp --recursive catppuccin-mocha.ini $out
'';
};

brightnessctl = lib.getExe pkgs.brightnessctl;
hyprctl = lib.getExe' pkgs.hyprland "hyprctl";
hyprlock = lib.getExe pkgs.hyprlock;
Expand Down
2 changes: 1 addition & 1 deletion home-manager/programs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
./dircolors.nix
./direnv.nix
./fd.nix
./fish.nix
./fish
./git.nix
./gpg.nix
./rbw.nix
Expand Down
61 changes: 0 additions & 61 deletions home-manager/programs/fish.nix

This file was deleted.

9 changes: 9 additions & 0 deletions home-manager/programs/fish/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
imports = [
./shell_abbrs.nix
./functions.nix
./interactive_shell_init.nix
];

programs.fish.enable = true;
}
144 changes: 144 additions & 0 deletions home-manager/programs/fish/functions.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
lib,
pkgs,
...
}: let
grep = lib.getExe pkgs.gnugrep;
nix = lib.getExe pkgs.nix;
sed = lib.getExe pkgs.gnused;
tr = lib.getExe' pkgs.coreutils "tr";
wc = lib.getExe' pkgs.coreutils "wc";
in {
programs.fish.functions = {
nixpkg-run = "${nix} run nixpkgs#$argv[1] -- $argv[2..]";

__prompt_space = ''
set_color normal
echo -n -s " "
'';

__prompt_segment = ''
# Get colours
set -l bg $argv[1]
set -l fg $argv[2]
# Set 'em
set_color -b $bg
set_color $fg
# Print text
if [ -n "$argv[3]" ]
echo -n -s $argv[3]
end
'';

__show_shlvl_user_host = ''
set -l bg white
set -l fg black
if [ -n "$SSH_CLIENT" ]
set bg blue # indicator for remote sessions
end
set -l who (whoami)
set -l host (hostname -s)
__prompt_segment $bg $fg \uf489" $SHLVL $who"
if [ "$who" != "$host" ]
# Skip @host bit if hostname == username
__prompt_segment $bg $fg "@$host"
end
'';

__show_jobs = ''
set -l jobs (jobs | ${wc} -l)
if [ $jobs -ne 0 ]
__prompt_space
__prompt_segment yellow black "$jobs"\ueba2" "
end
'';

__show_retval = ''
if [ $RETVAL -ne 0 ]
__prompt_space
__prompt_segment red black "$RETVAL"\uea87" "
end
'';

__show_venv = ''
if set -q VIRTUAL_ENV
__prompt_space
if [ "$VIRTUAL_ENV_PROJECT-" = "-" ]
__set_venv_project # try setting it manually
end
__prompt_segment yellow black \ued1b" $VIRTUAL_ENV_PROJECT"
end
'';

__set_venv_project = {
onVariable = "VIRTUAL_ENV";
body = ''
if test -e "$VIRTUAL_ENV/pyvenv.cfg"
set -g VIRTUAL_ENV_PROJECT (
${grep} "^prompt\s*=\s*" "$VIRTUAL_ENV/pyvenv.cfg" |
${sed} \
-e "s/^prompt\s*=\s*//" \
-e "s/\(.*\)-py\([[:digit:]]\.*[[:digit:]]*\)/\2:\1/"
)
else if test -e "$VIRTUAL_ENV/.project"
set -g VIRTUAL_ENV_PROJECT (cat "$VIRTUAL_ENV/.project")
end
'';
};

__show_git_prompt = ''
set -l prompt (fish_git_prompt)
if test -n "$prompt"
__prompt_space
__prompt_segment cyan black \ue65d(
echo $prompt |
${sed} --regexp-extended \
--expr 's/[()]//g' \
--expr 's|([^/])[a-zA-Z]*/|\1/|' \
--expr 's|^((./)?[A-Z]+-[0-9]+).*|\1|' \
--expr 's/^(.{16}).*/\1…/' |
${tr} '[:upper:]' '[:lower:]'
)
end
'';

__show_pwd = ''
__prompt_space
__prompt_segment black white \uea83" "(prompt_pwd)
'';

__show_prompt = ''
set -l uid (id -u $USER)
if [ $uid -eq 0 ]
__prompt_space
__prompt_segment red black "#"
else
__prompt_space
__prompt_segment normal white '$'
end
'';

fish_prompt = ''
set -g RETVAL $status
__show_shlvl_user_host
__show_venv
__show_git_prompt
__show_pwd
__show_prompt
__prompt_space
set_color normal
'';

fish_right_prompt = ''
__show_retval
__show_jobs
set_color normal
'';
};
}
18 changes: 18 additions & 0 deletions home-manager/programs/fish/interactive_shell_init.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
lib,
pkgs,
...
}: let
any-nix-shell = lib.getExe pkgs.any-nix-shell;
direnv = lib.getExe pkgs.direnv;
zoxide = lib.getExe pkgs.zoxide;
in {
programs.fish.interactiveShellInit = ''
set --universal fish_greeting
source ${pkgs.fzf}/share/fish/vendor_functions.d/fzf_key_bindings.fish
source ${pkgs.fzf}/share/fish/vendor_conf.d/load-fzf-key-bindings.fish
${zoxide} init --cmd cd fish | source
${any-nix-shell} fish | source
${direnv} hook fish | source
'';
}
Loading

0 comments on commit 289b414

Please sign in to comment.