From 23d2661e82c2bfe6f02a55c39d3cd77f661d4a58 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 10 Jul 2024 15:10:56 +0200 Subject: Add mise into bash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- .bashrc | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 13 deletions(-) (limited to '.bashrc') diff --git a/.bashrc b/.bashrc index 93954b0..468bf5f 100644 --- a/.bashrc +++ b/.bashrc @@ -92,7 +92,6 @@ export LESS="FSRX" export PAGER=less # git thingies. -source_maybe "$HOME/.gitcompletion.sh" alias gti=git # Setting up PS1. @@ -101,9 +100,6 @@ PS1='\u:\w$(__git_ps1 "\[\033[0;32m\]@%s\[\033[0m\]\]") $ ' # Introduce `cclip` as a fast way to use `xclip` but selecting the clipboard. alias cclip='xclip -selection clipboard' -# g completion -source_maybe "$HOME/.gcompletion.sh" - ## # Programming languages and environments. @@ -127,6 +123,9 @@ export GOPATH=$HOME # The g utility. See: https://github.com/mssola/g source_maybe "$HOME/.g.sh" +source_maybe "$HOME/.gcompletion.sh" + +# Git prompt. source_maybe "$HOME/.git-prompt.sh" # Complete the `docker` command if possible. @@ -149,10 +148,6 @@ alias random_string="cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head - # Cargo environment. source_maybe "$HOME/.cargo/env" -# This is relevant for the alternative switching globally, otherwise I keep -# linking shit up. -export NODE_VERSION="20" - ## # Lastly I had some problems with the GPG agent recently. So I copied a solution # from https://github.com/jessfraz/dotfiles @@ -191,9 +186,57 @@ if command -v rustc &> /dev/null; then fi fi -# Yarn thingies. -export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH" +## +# $ mise activate bash >> .bashrc + +export MISE_SHELL=bash +export __MISE_ORIG_PATH="$PATH" -# Finally RVM requires it to be the last thing on the PATH. -[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" -export PATH="$PATH:$HOME/.rvm/bin" +mise() { + local command + command="${1:-}" + if [ "$#" = 0 ]; then + command mise + return + fi + shift + + case "$command" in + deactivate|s|shell) + # if argv doesn't contains -h,--help + if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then + eval "$(command mise "$command" "$@")" + return $? + fi + ;; + esac + command mise "$command" "$@" +} + +_mise_hook() { + local previous_exit_status=$?; + eval "$(mise hook-env -s bash)"; + return $previous_exit_status; +}; +if [[ ";${PROMPT_COMMAND:-};" != *";_mise_hook;"* ]]; then + PROMPT_COMMAND="_mise_hook${PROMPT_COMMAND:+;$PROMPT_COMMAND}" +fi +if [ -z "${_mise_cmd_not_found:-}" ]; then + _mise_cmd_not_found=1 + if [ -n "$(declare -f command_not_found_handle)" ]; then + _mise_cmd_not_found_handle=$(declare -f command_not_found_handle) + eval "${_mise_cmd_not_found_handle/command_not_found_handle/_command_not_found_handle}" + fi + + command_not_found_handle() { + if mise hook-not-found -s bash -- "$1"; then + _mise_hook + "$@" + elif [ -n "$(declare -f _command_not_found_handle)" ]; then + _command_not_found_handle "$@" + else + echo "bash: command not found: $1" >&2 + return 127 + fi + } +fi -- cgit v1.2.3