diff --git a/.config/fish/conf.d/plugin-foreign-env.fish b/.config/fish/conf.d/plugin-foreign-env.fish new file mode 120000 index 00000000..caa6b140 --- /dev/null +++ b/.config/fish/conf.d/plugin-foreign-env.fish @@ -0,0 +1 @@ +/nix/store/phhybc3335vyvgmlsa1n4cmk9nvwd0lg-home-manager-files/.config/fish/conf.d/plugin-foreign-env.fish \ No newline at end of file diff --git a/.config/fish/config.fish b/.config/fish/config.fish new file mode 120000 index 00000000..9fc152c3 --- /dev/null +++ b/.config/fish/config.fish @@ -0,0 +1 @@ +/nix/store/phhybc3335vyvgmlsa1n4cmk9nvwd0lg-home-manager-files/.config/fish/config.fish \ No newline at end of file diff --git a/.config/fish/fish_variables b/.config/fish/fish_variables new file mode 100644 index 00000000..1a82b8ad --- /dev/null +++ b/.config/fish/fish_variables @@ -0,0 +1,31 @@ +# This file contains fish universal variable definitions. +# VERSION: 3.0 +SETUVAR __fish_initialized:3400 +SETUVAR fish_color_autosuggestion:555\x1ebrblack +SETUVAR fish_color_cancel:\x2dr +SETUVAR fish_color_command:blue +SETUVAR fish_color_comment:red +SETUVAR fish_color_cwd:green +SETUVAR fish_color_cwd_root:red +SETUVAR fish_color_end:green +SETUVAR fish_color_error:brred +SETUVAR fish_color_escape:brcyan +SETUVAR fish_color_history_current:\x2d\x2dbold +SETUVAR fish_color_host:normal +SETUVAR fish_color_host_remote:yellow +SETUVAR fish_color_normal:normal +SETUVAR fish_color_operator:brcyan +SETUVAR fish_color_param:cyan +SETUVAR fish_color_quote:yellow +SETUVAR fish_color_redirection:cyan\x1e\x2d\x2dbold +SETUVAR fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_status:red +SETUVAR fish_color_user:brgreen +SETUVAR fish_color_valid_path:\x2d\x2dunderline +SETUVAR fish_key_bindings:fish_default_key_bindings +SETUVAR fish_pager_color_completion:normal +SETUVAR fish_pager_color_description:B3A06D\x1eyellow\x1e\x2di +SETUVAR fish_pager_color_prefix:normal\x1e\x2d\x2dbold\x1e\x2d\x2dunderline +SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan +SETUVAR fish_pager_color_selected_background:\x2dr diff --git a/.config/fish/functions/fish_prompt.fish b/.config/fish/functions/fish_prompt.fish new file mode 100644 index 00000000..8b1d19cc --- /dev/null +++ b/.config/fish/functions/fish_prompt.fish @@ -0,0 +1,90 @@ +function fish_prompt + set -l __last_command_exit_status $status + + if not set -q -g __fish_arrow_functions_defined + set -g __fish_arrow_functions_defined + function _git_branch_name + set -l branch (git symbolic-ref --quiet HEAD 2>/dev/null) + if set -q branch[1] + echo (string replace -r '^refs/heads/' '' $branch) + else + echo (git rev-parse --short HEAD 2>/dev/null) + end + end + + function _is_git_dirty + not command git diff-index --cached --quiet HEAD -- &>/dev/null + or not command git diff --no-ext-diff --quiet --exit-code &>/dev/null + end + + function _is_git_repo + type -q git + or return 1 + git rev-parse --git-dir >/dev/null 2>&1 + end + + function _hg_branch_name + echo (hg branch 2>/dev/null) + end + + function _is_hg_dirty + set -l stat (hg status -mard 2>/dev/null) + test -n "$stat" + end + + function _is_hg_repo + fish_print_hg_root >/dev/null + end + + function _repo_branch_name + _$argv[1]_branch_name + end + + function _is_repo_dirty + _is_$argv[1]_dirty + end + + function _repo_type + if _is_hg_repo + echo hg + return 0 + else if _is_git_repo + echo git + return 0 + end + return 1 + end + end + + set -l cyan (set_color -o cyan) + set -l yellow (set_color -o yellow) + set -l red (set_color -o red) + set -l green (set_color -o green) + set -l blue (set_color -o blue) + set -l normal (set_color normal) + + set -l arrow_color "$green" + if test $__last_command_exit_status != 0 + set arrow_color "$red" + end + + set -l arrow "$arrow_color➜ " + if fish_is_root_user + set arrow "$arrow_color# " + end + + set -l cwd $cyan(basename (prompt_pwd)) + + set -l repo_info + if set -l repo_type (_repo_type) + set -l repo_branch $red(_repo_branch_name $repo_type) + set repo_info "$blue $repo_type:($repo_branch$blue)" + + if _is_repo_dirty $repo_type + set -l dirty "$yellow ✗" + set repo_info "$repo_info$dirty" + end + end + + echo -n -s $arrow ' '$cwd $repo_info $normal ' ' +end diff --git a/.config/home-manager/home.nix b/.config/home-manager/home.nix index e5af26da..60f9a6f3 100644 --- a/.config/home-manager/home.nix +++ b/.config/home-manager/home.nix @@ -1,11 +1,11 @@ -{ config, pkgs, isDarwin, ... }: +{ config, pkgs, ... }: { # Home Manager needs a bit of information about you and the # paths it should manage. home.username = "kachick"; # TODO: How to cover lima? The default is /home/kachick.local - home.homeDirectory = if isDarwin then "/Users/${config.home.username}" else "/home/${config.home.username}"; + home.homeDirectory = if pkgs.stdenv.hostPlatform.isDarwin then "/Users/${config.home.username}" else "/home/${config.home.username}"; xdg.configHome = "${config.home.homeDirectory}/.config"; xdg.cacheHome = "${config.home.homeDirectory}/.cache"; xdg.stateHome = "${config.home.homeDirectory}/.local/state"; @@ -24,6 +24,46 @@ # Let Home Manager install and manage itself. programs.home-manager.enable = true; + programs.fish = { + enable = true; + + shellInit = + '' + # nix + if test -e "$HOME/.nix-profile/etc/profile.d/nix.sh" + fenv source "$HOME/.nix-profile/etc/profile.d/nix.sh" + end + + # home-manager + if test -e "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" + fenv source "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" + end + + # starship + if status is-interactive + starship init fish | source + end + ''; + + shellAliases = { + la = "exa --long --all --group-directories-first"; + }; + + plugins = [{ + name = "foreign-env"; + src = pkgs.fetchFromGitHub { + owner = "oh-my-fish"; + repo = "plugin-foreign-env"; + rev = "3ee95536106c11073d6ff466c1681cde31001383"; + sha256 = "sha256-vyW/X2lLjsieMpP9Wi2bZPjReaZBkqUbkh15zOi8T4Y="; + }; + }]; + }; + + programs.direnv.enable = true; + + programs.zoxide.enable = true; + # TODO: Consider to manage nix.conf with home-manager. However it includes`trusted-public-keys` # nix.package = pkgs.nix; # nix.settings = { @@ -49,6 +89,7 @@ pkgs.zsh # Don't include bash - https://github.com/NixOS/nixpkgs/issues/29960, https://github.com/NixOS/nix/issues/730 # pkgs.bash + pkgs.fish pkgs.nushell pkgs.starship pkgs.jq diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 52660e52..fffc2262 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -8,6 +8,7 @@ "foxundermoon.shell-format", "tamasfe.even-better-toml", "jnoortheen.nix-ide", - "thenuprojectcontributors.vscode-nushell-lang" + "thenuprojectcontributors.vscode-nushell-lang", + "bmalehorn.vscode-fish" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 0c913feb..04311688 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,9 @@ "[nix]": { "editor.defaultFormatter": "jnoortheen.nix-ide" }, + "[fish]": { + "editor.defaultFormatter": "bmalehorn.vscode-fish" + }, "nix.serverPath": "nil", "nix.enableLanguageServer": true, "nix.serverSettings": { diff --git a/home/.aliases.sh b/home/.aliases.sh index ca3b69f8..d055288b 100644 --- a/home/.aliases.sh +++ b/home/.aliases.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash alias git-switch-default='git checkout main 2>/dev/null || git checkout master 2>/dev/null' -alias git-upsteram="git remote | grep -E '^upstream$'|| git remote | grep -E '^origin$'" +alias git-upstream="git remote | grep -E '^upstream$'|| git remote | grep -E '^origin$'" # https://github.com/kyanny/git-delete-merged-branches/pull/6 alias git-delete-merged-branches="git branch --merged | grep -vE '((^\*)|^ *(main|master)$)' | xargs -I % git branch -d %" -alias git-cleanup-branches='git-switch-default && git pull $(git-upsteram) $(git current-branch) && git fetch $(git-upsteram) --tags --prune && git-delete-merged-branches' +alias git-cleanup-branches='git-switch-default && git pull $(git-upstream) $(git current-branch) && git fetch $(git-upstream) --tags --prune && git-delete-merged-branches' alias la='exa --long --all --group-directories-first'