Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fish #178

Merged
merged 9 commits into from
Jul 14, 2023
Merged

Fish #178

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
1 change: 1 addition & 0 deletions .config/fish/conf.d/plugin-foreign-env.fish
1 change: 1 addition & 0 deletions .config/fish/config.fish
31 changes: 31 additions & 0 deletions .config/fish/fish_variables
Original file line number Diff line number Diff line change
@@ -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
90 changes: 90 additions & 0 deletions .config/fish/functions/fish_prompt.fish
Original file line number Diff line number Diff line change
@@ -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
45 changes: 43 additions & 2 deletions .config/home-manager/home.nix
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 = {
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"[nix]": {
"editor.defaultFormatter": "jnoortheen.nix-ide"
},
"[fish]": {
"editor.defaultFormatter": "bmalehorn.vscode-fish"
},
"nix.serverPath": "nil",
"nix.enableLanguageServer": true,
"nix.serverSettings": {
Expand Down
4 changes: 2 additions & 2 deletions home/.aliases.sh
Original file line number Diff line number Diff line change
@@ -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'

Expand Down