diff --git a/dot_config/fish/conf.d/_pure_init.fish b/dot_config/fish/conf.d/_pure_init.fish new file mode 100644 index 0000000..1b56b3d --- /dev/null +++ b/dot_config/fish/conf.d/_pure_init.fish @@ -0,0 +1,40 @@ +# Deactivate the default virtualenv prompt so that we can add our own +set --global --export VIRTUAL_ENV_DISABLE_PROMPT 1 + +# Whether or not is a fresh session +set --global _pure_fresh_session true + +# Register `_pure_prompt_new_line` as an event handler fot `fish_prompt` +functions --query _pure_prompt_new_line + +function _pure_uninstall --on-event pure_uninstall + rm -f $__fish_config_dir/conf.d/pure.fish + + # backup fish_prompt and fish_title to default + cp $__fish_config_dir/functions/fish_prompt{,.pure-backup}.fish + cp $__fish_config_dir/functions/fish_title{,.pure-backup}.fish + + # erase existing fish_prompt and fish_title to default + functions --erase fish_prompt + functions --erase fish_title + # restore fish_prompt and fish_title to default + cp {$__fish_data_dir,$__fish_config_dir}/functions/fish_prompt.fish + cp {$__fish_data_dir,$__fish_config_dir}/functions/fish_title.fish + + # refresh fish_prompt and fish_title definitions + source $__fish_data_dir/functions/fish_prompt.fish + source $__fish_data_dir/functions/fish_title.fish + + # erase _pure* variables + set --names \ + | string replace --filter --regex '(^_?pure)' 'set --erase $1' \ + | source + # erase _pure* functions + functions --names --all \ + | string replace --filter --regex '(^_?pure)' 'functions --erase $1' \ + | source + # delete _pure* files + for file in $__fish_config_dir/{functions,conf.d}/_pure_* + rm -f $file + end +end diff --git a/dot_config/fish/conf.d/fzf.fish b/dot_config/fish/conf.d/fzf.fish new file mode 100644 index 0000000..8156c11 --- /dev/null +++ b/dot_config/fish/conf.d/fzf.fish @@ -0,0 +1,28 @@ +# fzf.fish is only meant to be used in interactive mode. If not in interactive mode and not in CI, skip the config to speed up shell startup +if not status is-interactive && test "$CI" != true + exit +end + +# Because of scoping rules, to capture the shell variables exactly as they are, we must read +# them before even executing _fzf_search_variables. We use psub to store the +# variables' info in temporary files and pass in the filenames as arguments. +# This variable is global so that it can be referenced by fzf_configure_bindings and in tests +set --global _fzf_search_vars_command '_fzf_search_variables (set --show | psub) (set --names | psub)' + + +# Install the default bindings, which are mnemonic and minimally conflict with fish's preset bindings +fzf_configure_bindings + +# Doesn't erase autoloaded _fzf_* functions because they are not easily accessible once key bindings are erased +function _fzf_uninstall --on-event fzf_uninstall + _fzf_uninstall_bindings + + set --erase _fzf_search_vars_command + functions --erase _fzf_uninstall _fzf_migration_message _fzf_uninstall_bindings fzf_configure_bindings + complete --erase fzf_configure_bindings + + set_color cyan + echo "fzf.fish uninstalled." + echo "You may need to manually remove fzf_configure_bindings from your config.fish if you were using custom key bindings." + set_color normal +end diff --git a/dot_config/fish/conf.d/hydro.fish b/dot_config/fish/conf.d/hydro.fish new file mode 100644 index 0000000..72afd5c --- /dev/null +++ b/dot_config/fish/conf.d/hydro.fish @@ -0,0 +1,137 @@ +status is-interactive || exit + +set --global _hydro_git _hydro_git_$fish_pid + +function $_hydro_git --on-variable $_hydro_git + commandline --function repaint +end + +function _hydro_pwd --on-variable PWD --on-variable hydro_ignored_git_paths --on-variable fish_prompt_pwd_dir_length + set --local git_root (command git --no-optional-locks rev-parse --show-toplevel 2>/dev/null) + set --local git_base (string replace --all --regex -- "^.*/" "" "$git_root") + set --local path_sep / + + test "$fish_prompt_pwd_dir_length" = 0 && set path_sep + + if set --query git_root[1] && ! contains -- $git_root $hydro_ignored_git_paths + set --erase _hydro_skip_git_prompt + else + set --global _hydro_skip_git_prompt + end + + set --global _hydro_pwd ( + string replace --ignore-case -- ~ \~ $PWD | + string replace -- "/$git_base/" /:/ | + string replace --regex --all -- "(\.?[^/]{"( + string replace --regex --all -- '^$' 1 "$fish_prompt_pwd_dir_length" + )"})[^/]*/" "\$1$path_sep" | + string replace -- : "$git_base" | + string replace --regex -- '([^/]+)$' "\x1b[1m\$1\x1b[22m" | + string replace --regex --all -- '(?!^/$)/|^$' "\x1b[2m/\x1b[22m" + ) +end + +function _hydro_postexec --on-event fish_postexec + set --local last_status $pipestatus + set --global _hydro_status "$_hydro_newline$_hydro_color_prompt$hydro_symbol_prompt" + + for code in $last_status + if test $code -ne 0 + set --global _hydro_status "$_hydro_color_error| "(echo $last_status)" $_hydro_newline$_hydro_color_prompt$_hydro_color_error$hydro_symbol_prompt" + break + end + end + + test "$CMD_DURATION" -lt $hydro_cmd_duration_threshold && set _hydro_cmd_duration && return + + set --local secs (math --scale=1 $CMD_DURATION/1000 % 60) + set --local mins (math --scale=0 $CMD_DURATION/60000 % 60) + set --local hours (math --scale=0 $CMD_DURATION/3600000) + + set --local out + + test $hours -gt 0 && set --local --append out $hours"h" + test $mins -gt 0 && set --local --append out $mins"m" + test $secs -gt 0 && set --local --append out $secs"s" + + set --global _hydro_cmd_duration "$out " +end + +function _hydro_prompt --on-event fish_prompt + set --query _hydro_status || set --global _hydro_status "$_hydro_newline$_hydro_color_prompt$hydro_symbol_prompt" + set --query _hydro_pwd || _hydro_pwd + + command kill $_hydro_last_pid 2>/dev/null + + set --query _hydro_skip_git_prompt && set $_hydro_git && return + + fish --private --command " + set branch ( + command git symbolic-ref --short HEAD 2>/dev/null || + command git describe --tags --exact-match HEAD 2>/dev/null || + command git rev-parse --short HEAD 2>/dev/null | + string replace --regex -- '(.+)' '@\$1' + ) + + test -z \"\$$_hydro_git\" && set --universal $_hydro_git \"\$branch \" + + ! command git diff-index --quiet HEAD 2>/dev/null || + count (command git ls-files --others --exclude-standard) >/dev/null && set info \"$hydro_symbol_git_dirty\" + + for fetch in $hydro_fetch false + command git rev-list --count --left-right @{upstream}...@ 2>/dev/null | + read behind ahead + + switch \"\$behind \$ahead\" + case \" \" \"0 0\" + case \"0 *\" + set upstream \" $hydro_symbol_git_ahead\$ahead\" + case \"* 0\" + set upstream \" $hydro_symbol_git_behind\$behind\" + case \* + set upstream \" $hydro_symbol_git_ahead\$ahead $hydro_symbol_git_behind\$behind\" + end + + set --universal $_hydro_git \"\$branch\$info\$upstream \" + + test \$fetch = true && command git fetch --no-tags 2>/dev/null + end + " & + + set --global _hydro_last_pid $last_pid +end + +function _hydro_fish_exit --on-event fish_exit + set --erase $_hydro_git +end + +function _hydro_uninstall --on-event hydro_uninstall + set --names | + string replace --filter --regex -- "^(_?hydro_)" "set --erase \$1" | + source + functions --erase (functions --all | string match --entire --regex "^_?hydro_") +end + +set --global hydro_color_normal (set_color normal) + +for color in hydro_color_{pwd,git,error,prompt,duration} + function $color --on-variable $color --inherit-variable color + set --query $color && set --global _$color (set_color $$color) + end && $color +end + +function hydro_multiline --on-variable hydro_multiline + if test "$hydro_multiline" = true + set --global _hydro_newline "\n" + else + set --global _hydro_newline "" + end +end && hydro_multiline + +set --query hydro_color_error || set --global hydro_color_error $fish_color_error +set --query hydro_symbol_prompt || set --global hydro_symbol_prompt ❱ +set --query hydro_symbol_git_dirty || set --global hydro_symbol_git_dirty • +set --query hydro_symbol_git_ahead || set --global hydro_symbol_git_ahead ↑ +set --query hydro_symbol_git_behind || set --global hydro_symbol_git_behind ↓ +set --query hydro_multiline || set --global hydro_multiline false +set --query hydro_cmd_duration_threshold || set --global hydro_cmd_duration_threshold 1000 diff --git a/dot_config/fish/conf.d/keychain.fish b/dot_config/fish/conf.d/keychain.fish new file mode 100644 index 0000000..a3c9da4 --- /dev/null +++ b/dot_config/fish/conf.d/keychain.fish @@ -0,0 +1,7 @@ +if status is-interactive + keychain --quiet -Q id_ed25519 +end + +if test -f ~/.keychain/$hostname-fish + source ~/.keychain/$hostname-fish +end diff --git a/dot_config/fish/conf.d/nvm.fish b/dot_config/fish/conf.d/nvm.fish new file mode 100644 index 0000000..e060f2f --- /dev/null +++ b/dot_config/fish/conf.d/nvm.fish @@ -0,0 +1,28 @@ +set --query nvm_mirror || set --global nvm_mirror https://nodejs.org/dist +set --query XDG_DATA_HOME || set --local XDG_DATA_HOME ~/.local/share +set --global nvm_data $XDG_DATA_HOME/nvm + +function _nvm_install --on-event nvm_install + test ! -d $nvm_data && command mkdir -p $nvm_data + echo "Downloading the Node distribution index..." 2>/dev/null + _nvm_index_update +end + +function _nvm_update --on-event nvm_update + set --query --universal nvm_data && set --erase --universal nvm_data + set --query --universal nvm_mirror && set --erase --universal nvm_mirror + set --query nvm_mirror || set --global nvm_mirror https://nodejs.org/dist +end + +function _nvm_uninstall --on-event nvm_uninstall + command rm -rf $nvm_data + + set --query nvm_current_version && _nvm_version_deactivate $nvm_current_version + + set --names | string replace --filter --regex -- "^nvm" "set --erase nvm" | source + functions --erase (functions --all | string match --entire --regex -- "^_nvm_") +end + +if status is-interactive && set --query nvm_default_version && ! set --query nvm_current_version + nvm use --silent $nvm_default_version +end diff --git a/dot_config/fish/conf.d/pure.fish b/dot_config/fish/conf.d/pure.fish new file mode 100644 index 0000000..8e11f07 --- /dev/null +++ b/dot_config/fish/conf.d/pure.fish @@ -0,0 +1,115 @@ +set --global pure_version 4.11.0 # For bug report and tag-after-merge workflow + +# Base colors +_pure_set_default pure_color_primary blue +_pure_set_default pure_color_info cyan +_pure_set_default pure_color_mute brblack +_pure_set_default pure_color_success magenta +_pure_set_default pure_color_normal normal +_pure_set_default pure_color_danger red +_pure_set_default pure_color_light white +_pure_set_default pure_color_warning yellow +_pure_set_default pure_color_dark black + +# Prompt +_pure_set_default pure_symbol_prompt "❯" +_pure_set_default pure_symbol_reverse_prompt "❮" # used for VI mode +_pure_set_default pure_color_prompt_on_error pure_color_danger +_pure_set_default pure_color_prompt_on_success pure_color_success + +# Current Working Directory +_pure_set_default pure_color_current_directory pure_color_primary +_pure_set_default pure_shorten_prompt_current_directory_length 0 +_pure_set_default pure_truncate_prompt_current_directory_keeps -1 + +# Git +_pure_set_default pure_enable_git true +_pure_set_default pure_symbol_git_unpulled_commits "⇣" +_pure_set_default pure_symbol_git_unpushed_commits "⇡" +_pure_set_default pure_symbol_git_dirty "*" +_pure_set_default pure_symbol_git_stash "≡" +_pure_set_default pure_color_git_unpulled_commits pure_color_info +_pure_set_default pure_color_git_unpushed_commits pure_color_info +_pure_set_default pure_color_git_branch pure_color_mute +_pure_set_default pure_color_git_dirty pure_color_mute +_pure_set_default pure_color_git_stash pure_color_info + +# Remote info (user@hostname) for SSH and containers (Docker/LXC) +_pure_set_default pure_color_hostname pure_color_mute +_pure_set_default pure_color_at_sign pure_color_mute +_pure_set_default pure_color_username_normal pure_color_mute +_pure_set_default pure_color_username_root pure_color_light + +# Number of running jobs +_pure_set_default pure_show_jobs false +_pure_set_default pure_color_jobs pure_color_normal + +# Show system time +_pure_set_default pure_show_system_time false +_pure_set_default pure_color_system_time pure_color_mute + +# Nix build environment +_pure_set_default pure_enable_nixdevshell false +_pure_set_default pure_symbol_nixdevshell_prefix "❄️" # otherwise nerdfonts: '󱄅' or '' +_pure_set_default pure_color_nixdevshell_prefix pure_color_info +_pure_set_default pure_color_nixdevshell_symbol pure_color_mute + +# env for Python +_pure_set_default pure_enable_virtualenv true +_pure_set_default pure_symbol_virtualenv_prefix "" # 🐍 +_pure_set_default pure_color_virtualenv pure_color_mute + +# AWS profile name +_pure_set_default pure_enable_aws_profile true +_pure_set_default pure_symbol_aws_profile_prefix "" # ☁️ +_pure_set_default pure_color_aws_profile pure_color_warning + +# Print current working directory at the beginning of prompt +# true (default): current directory, git, user@hostname (ssh-only), command duration +# false: user@hostname (ssh-only), current directory, git, command duration +_pure_set_default pure_begin_prompt_with_current_directory true + +# Show exit code of last command as a separate prompt character (cf. https://github.com/sindresorhus/pure/wiki#show-exit-code-of-last-command-as-a-separate-prompt-character) +# false - single prompt character, default +# true - separate prompt character +_pure_set_default pure_separate_prompt_on_error false + +# Max execution time of a process before its run time is shown when it exits +_pure_set_default pure_threshold_command_duration 5 +_pure_set_default pure_show_subsecond_command_duration false +_pure_set_default pure_color_command_duration pure_color_warning + +# VI mode indicator +# true (default): indicate a non-insert mode by reversing the prompt symbol (❮) +# false: indicate vi mode with [I], [N], [V] +_pure_set_default pure_reverse_prompt_symbol_in_vimode true + +# Title +_pure_set_default pure_symbol_title_bar_separator - +_pure_set_default pure_shorten_window_title_current_directory_length 0 +_pure_set_default pure_truncate_window_title_current_directory_keeps -1 + +# Check for new release on startup +_pure_set_default pure_check_for_new_release false + +# Prefix prompt when logged in as root +_pure_set_default pure_show_prefix_root_prompt false +_pure_set_default pure_symbol_prefix_root_prompt "#" +_pure_set_default pure_color_prefix_root_prompt pure_color_danger + +# Compact mode +_pure_set_default pure_enable_single_line_prompt false + +# Detect when running in container (e.g. docker, podman, LXC/LXD) +_pure_set_default pure_enable_container_detection true +_pure_set_default pure_symbol_container_prefix "" # suggestion: '🐋' or '📦' + +# Detect when running in SSH +_pure_set_default pure_symbol_ssh_prefix "" # suggestion: 'ssh:/' or '🔗🔐🔒🌐' + +# Display Kubernetes/k8s context and namespace +_pure_set_default pure_enable_k8s false +_pure_set_default pure_symbol_k8s_prefix "☸" # ☸️ +_pure_set_default pure_color_k8s_prefix pure_color_info +_pure_set_default pure_color_k8s_context pure_color_success +_pure_set_default pure_color_k8s_namespace pure_color_primary diff --git a/dot_config/fish/conf.d/starship.fish b/dot_config/fish/conf.d/starship.fish new file mode 100644 index 0000000..c179c03 --- /dev/null +++ b/dot_config/fish/conf.d/starship.fish @@ -0,0 +1 @@ +starship init fish | source