-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge MR 'feat(shell): migrate from bash to fish shell' into 'main'
See merge request el-capitano/dotfiles!389
- Loading branch information
Showing
23 changed files
with
350 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -325,3 +325,6 @@ packages: | |
- name: atc0005/[email protected] | ||
description: Small CLI tool used to submit messages to Microsoft Teams | ||
link: https://github.com/atc0005/send2teams | ||
- name: sharkdp/[email protected] | ||
description: A simple, fast and user-friendly alternative to 'find' | ||
link: https://github.com/sharkdp/fd |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env fish | ||
|
||
abbr --add fish-reload-config 'source ~/.config/fish/**/*.fish' | ||
abbr --add g_commit_and_push --set-cursor 'git commit -am "%" && git push' | ||
abbr --add starwars 'telnet towel.blinkenlights.nl' | ||
abbr --add agi 'aqua g -g -i' | ||
|
||
|
||
abbr --position anywhere --add p0 "&> /dev/null" # Pipe everything to /dev/null | ||
|
||
# Function to set abbreviation if command exists | ||
function set_abbr_if_cmd_exists | ||
set -l cmd $argv[1] | ||
set -l abbr_name $argv[2] | ||
set -l abbr_value $argv[3] | ||
if command -v $cmd >/dev/null | ||
abbr -a $abbr_name $abbr_value | ||
end | ||
end | ||
|
||
# Function to set environment variable if command exists | ||
function set_env_if_cmd_exists | ||
set -l cmd $argv[1] | ||
set -l var_name $argv[2] | ||
set -l var_value $argv[3] | ||
if command -v $cmd >/dev/null | ||
set -gx $var_name $var_value | ||
end | ||
end | ||
|
||
# Aqua installed tools | ||
set_abbr_if_cmd_exists eza ls eza | ||
set_abbr_if_cmd_exists eza ll "eza -al" | ||
set_abbr_if_cmd_exists bat cat bat | ||
set_abbr_if_cmd_exists gping ping gping | ||
set_abbr_if_cmd_exists hwatch watch hwatch | ||
set_abbr_if_cmd_exists lazydocker lzd lazydocker | ||
set_abbr_if_cmd_exists lazygit lzg lazygit | ||
|
||
# Mise installed tools | ||
set_env_if_cmd_exists moar PAGER "moar -no-clear-on-exit" | ||
set_abbr_if_cmd_exists pgcli psql pgcli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Repeats the last command with `sudo` prefix | ||
alias pls='sudo $history[1]' | ||
|
||
# Needed for granted to work, see: https://docs.commonfate.io/granted/internals/shell-alias#grantedinternalsshell-alias | ||
alias assume="source "$(dirname $(aqua which assume))"/assume.fish" | ||
|
||
# Terraform aliases | ||
alias tfapply='terraform apply plan.tfplan' | ||
alias tfcopyplan='terraform show -no-color plan.tfplan | pbcopy' | ||
alias tfplan='terraform plan -out=plan.tfplan' | ||
|
||
# Helpers for working with Clipboard | ||
alias pbcopy='xclip -selection clipboard' | ||
alias pbpaste='xclip -selection clipboard -o' | ||
alias cb='flatpak run app.getclipboard.Clipboard' | ||
|
||
# Provision Hetzner GitLab Runners using scheduled pipelines trigger | ||
alias gl_runner_up='glab -R el-capitano/operations/hetzner-cloud-runners schedule run 2691862' | ||
alias gl_runner_down='glab -R el-capitano/operations/hetzner-cloud-runners schedule run 383558' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Set Aqua variables and paths | ||
if set -q XDG_DATA_HOME | ||
set -gx AQUA_ROOT_DIR "$XDG_DATA_HOME/aquaproj-aqua" | ||
else | ||
set -gx AQUA_ROOT_DIR "$HOME/.local/share/aquaproj-aqua" | ||
end | ||
|
||
set -gx PATH "$AQUA_ROOT_DIR/bin" $PATH | ||
|
||
if set -q XDG_CONFIG_HOME | ||
set -gx AQUA_GLOBAL_CONFIG "$XDG_CONFIG_HOME/aquaproj-aqua/aqua.yaml" | ||
else | ||
set -gx AQUA_GLOBAL_CONFIG "$HOME/.config/aquaproj-aqua/aqua.yaml" | ||
end | ||
|
||
set -gx AQUA_GENERATE_WITH_DETAIL true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
############################################## | ||
# BITWARDEN: auto load tokens if DB unlocked # | ||
############################################## | ||
|
||
function __load_tokens_if_rbw_unlocks --on-event rbw-unlocked | ||
if command -v rbw >/dev/null 2>&1 | ||
if rbw unlocked >/dev/null 2>&1 | ||
echo "🔓🗝️ Session unlocked, loading tokens from Bitwarden... 🔓🗝️" | ||
|
||
load_token OPENAI_API_KEY | ||
load_token GITLAB_TOKEN TF_HTTP_PASSWORD TF_VAR_gitlab_token GL_TOKEN LAB_CORE_TOKEN | ||
load_token GITHUB_TOKEN | ||
else | ||
echo "🔒 Bitwarden vault locked, not loading tokens. 🔒" | ||
echo "💡 To load tokens run the `reco` alias. 💡" | ||
end | ||
end | ||
end | ||
|
||
function load_token | ||
set -l token_name $argv[1] | ||
set -l token_value (rbw get $token_name) | ||
set -gx $token_name $token_value | ||
echo "🔓 $token_name" | ||
for alias in $argv[2..-1] | ||
set -gx $alias $token_value | ||
echo "🔓 $alias (alias of $token_name)" | ||
end | ||
end | ||
|
||
function reco | ||
rbw unlock | ||
emit rbw-unlocked | ||
end | ||
|
||
# Call one time to see if already unlocked. | ||
__load_tokens_if_rbw_unlocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Set fisher plugin path and load these plugins. | ||
# Source: https://github.com/jorgebucaran/fisher/issues/640#issuecomment-1878499811 | ||
set fisher_path $__fish_config_dir/plugins | ||
|
||
set fish_complete_path $fish_complete_path[1] $fisher_path/completions $fish_complete_path[2..] | ||
set fish_function_path $fish_function_path[1] $fisher_path/functions $fish_function_path[2..] | ||
|
||
for file in $fisher_path/conf.d/*.fish | ||
source $file | ||
end | ||
|
||
# | ||
# Helpers | ||
# | ||
|
||
# Source: https://www.reddit.com/r/fishshell/comments/1fmbypo/is_there_a_nicer_way_to_create_auto_complete_for/lo9vqzz/ | ||
function optspec2comp | ||
string replace -r / "\n-" $argv | | ||
string replace -r '^' - | | ||
string replace -r '=$' "" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Some nice resources | ||
# - https://www.reddit.com/r/fishshell/comments/1he9bd8/what_are_you_abbreviations/ | ||
# - https://www.reddit.com/r/fishshell/comments/1gp750x/can_i_see_your_fish_configs/ | ||
|
||
set -x TF_CLI_ARGS_plan "-lock=false" | ||
set -x TF_HTTP_USERNAME tmeijn | ||
|
||
fish_add_path $HOME/.krew/bin $HOME/.cargo/bin $HOME/.local/bin $HOME/bin | ||
|
||
# Everything below this should only be loaded on interactive shells. | ||
if ! status is-interactive | ||
mise activate fish --shims | source | ||
return 0 | ||
end | ||
|
||
if command -v mise &>/dev/null | ||
mise activate fish | source | ||
mise hook-env -s fish | source | ||
# Mise itself doesn't export this as a variable as Aqua does do, so we do it ourself. | ||
set -gx MISE_GLOBAL_CONFIG (mise config ls --no-header | head -n1 | awk '{print $1}') | ||
set -gx MISE_GLOBAL_CONFIG (string replace -a '~' $HOME $MISE_GLOBAL_CONFIG) | ||
end | ||
|
||
if command -v git-town &> /dev/null | ||
alias gt='git-town' | ||
end | ||
|
||
if command -v kubectl &>/dev/null | ||
function kubectl --wraps kubectl | ||
command kubecolor $argv | ||
end | ||
|
||
# adds alias for "k" to "kubecolor" with completions | ||
function k --wraps kubectl | ||
command kubecolor $argv | ||
end | ||
|
||
# Set `dyff` as the kubectl differ (k diff ...) | ||
set -x KUBECTL_EXTERNAL_DIFF "dyff between --omit-header --set-exit-code" | ||
end | ||
|
||
if command -v aws_completer &>/dev/null | ||
# Enable AWS CLI autocompletion: https://github.com/aws/aws-cli/issues/1079#issuecomment-541997810 | ||
complete --command aws --no-files --arguments '(begin; set --local --export COMP_SHELL fish; set --local --export COMP_LINE (commandline); aws_completer | sed \'s/ $//\'; end)' | ||
end | ||
|
||
# Only update completions once a day since this is a slow operation. | ||
if test ! -e $HOME/.update_completions_lock || test (math (date +%s) - (stat -c %Y $HOME/.update_completions_lock)) -gt 86400 | ||
update_completions | ||
echo "Updating completions..." | ||
touch $HOME/.update_completions_lock | ||
end | ||
|
||
# Can be used as fallback when rbw is broken. | ||
if test -f ~/.env | ||
set -gx (cat ~/.env | string split -f1 '=') | ||
end | ||
|
||
# ENHANCE! | ||
command -v fixit >/dev/null; and fixit init fish | source | ||
command -v zoxide >/dev/null; and zoxide init --cmd cd fish | source | ||
command -v atuin >/dev/null; and atuin init fish | source | ||
#command -v savvy >/dev/null; and savvy init fish | source # Disabled: not currently used, so saving in Fish startup costs. | ||
command -v starship >/dev/null; and starship init fish | source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
jorgebucaran/fisher | ||
nickeb96/puffer-fish | ||
jorgebucaran/replay.fish | ||
jorgebucaran/autopair.fish | ||
gazorby/fish-abbreviation-tips | ||
patrickf1/fzf.fish | ||
decors/fish-colored-man |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function benchmark \ | ||
--description 'benchmark a shell' \ | ||
--argument-names shellname | ||
|
||
test -n "$shellname" || set shellname fish | ||
echo "running $shellname 10 times..." | ||
for i in (seq 10) | ||
/usr/bin/time -f "\t%E real,\t%U user,\t%S sys" $shellname -i -c exit | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Function to check if a git repository has pending changes | ||
function check_git_status | ||
find . -type d -name ".git" ! -path "*/.terraform/modules*" -exec dirname {} \; | while read -l dir | ||
if test -d "$dir/.git" | ||
pushd "$dir" > /dev/null; or return | ||
if git status --porcelain | grep -q . | ||
echo "=== Pending changes in $dir ===" | ||
git status -s | ||
end | ||
popd > /dev/null; or return | ||
end | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
chezmoi/dot_config/fish/functions/profile_shell_startup.fish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function profile_shell_startup --description 'Profile fish shell startup time' | ||
set shellname fish | ||
set fprof $__fish_config_dir/fishprof.txt | ||
fish --profile-startup=$fprof -i -c exit | ||
awk 'NR==1 || $3==">"{print}' $fprof | string replace $HOME '~' | ||
|
||
read -l -P "Do you want to see the sorted profile results? (y/N) " confirm | ||
switch $confirm | ||
case Y y | ||
sort -nk2 $fprof | ||
case '' N n | ||
echo "Sorting skipped." | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
set -g tfinit_optspec 'b/backend=' no-plan | ||
|
||
function tfinit --description 'Initialize Terraform with an optional partial backend file.' | ||
argparse $tfinit_optspec -- $argv | ||
or return | ||
|
||
set -l init_args | ||
|
||
if test -f "backends/local.tfbackend" | ||
echo "Local backend file detected, setting in command" | ||
set -gx TF_CLI_ARGS_init "-backend-config=backends/local.tfbackend" | ||
end | ||
|
||
if set -q _flag_backend | ||
if not test -f "backends/$_flag_backend.tfbackend" | ||
echo "Backend file 'backends/$_flag_backend.tfbackend' does not exist!" | ||
return 1 | ||
end | ||
set init_args $init_args "-backend-config=backends/$_flag_backend.tfbackend" | ||
set -gx TF_VAR_env "$_flag_backend" | ||
end | ||
|
||
set init_args $init_args -reconfigure $argv | ||
|
||
terraform init $init_args | ||
|
||
if not set -q _flag_no_plan | ||
echo "==== Executing Terraform plan command... ====" | ||
terraform plan -out=plan.tfplan | ||
end | ||
end | ||
|
||
complete -f --command tfinit --arguments='(optspec2comp $tfinit_optspec)' |
Oops, something went wrong.