-
-
Save jesusalc/b14a57ec9024ff1a3889be6b2c968bb7 to your computer and use it in GitHub Desktop.
directory based history bash profile
This file contains hidden or 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
| #!/usr/bin/env bash | |
| #!/bin/bash | |
| # | |
| # .mycd von jesusalc | |
| # | |
| # REF https://gist.github.com/jesusalc/b14a57ec9024ff1a3889be6b2c968bb7 | |
| # | |
| if [ "${DEBUG-0}" -eq 0 ] ; then | |
| { | |
| typeset DEBUG=0 | |
| export DEBUG | |
| } | |
| fi | |
| function mycd_has_tty() { | |
| [[ -t 0 ]] && [[ -t 1 ]] && [[ -t 2 ]] | |
| } # end mycd_has_tty | |
| function mycd_is_interactive_shell() { | |
| case "$-" in | |
| *i*) return 0 ;; | |
| *) return 1 ;; | |
| esac | |
| } # end mycd_is_interactive_shell | |
| function mycd_should_activate() { | |
| mycd_is_interactive_shell || return 1 | |
| mycd_has_tty || return 1 | |
| [[ "${TERM-}" != "dumb" ]] || return 1 | |
| [[ "${MYCD_DISABLE-0}" != "1" ]] || return 1 | |
| [[ -z "${CI-}" ]] || return 1 | |
| if [[ "${MYCD_DISABLE_CHILD_SHELLS-1}" == "1" && -n "${MYCD_SESSION_OWNER_PID-}" && "${MYCD_SESSION_OWNER_PID}" != "$$" ]] ; then | |
| { | |
| return 1 | |
| } | |
| fi | |
| if [[ -n "${MYCD_MAX_SHLVL-}" && "${SHLVL:-1}" -gt "${MYCD_MAX_SHLVL}" ]] ; then | |
| { | |
| return 1 | |
| } | |
| fi | |
| return 0 | |
| } # end mycd_should_activate | |
| if mycd_should_activate ; then | |
| { | |
| export MYCD_SESSION_OWNER_PID="$$" | |
| # if mesg n ; then # set not empty -IF DEFINED AND HAS SOMETHING GO IN(o> | |
| # { | |
| # echo hola | |
| # exec 3>&1 4>&2 >>"${_log_file}" 2>&1 # How to redirect output REF: https://stackoverflow.co> | |
| # _mycd_no_wall_broadcast_no_banner=1 | |
| # _mycd_running=1 | |
| function type_function_exists() { | |
| type "$1" > /dev/null 2>&1 | |
| } # type_function_exists | |
| export MYCD_ENABLE_VERSION_MANAGERS="${MYCD_ENABLE_VERSION_MANAGERS:-0}" | |
| export MYCD_ALLOW_INSTALLS="${MYCD_ALLOW_INSTALLS:-0}" | |
| export MYCD_ENABLE_AUTOEXEC="${MYCD_ENABLE_AUTOEXEC:-0}" | |
| export MYCD_ENABLE_GIT_STATUS="${MYCD_ENABLE_GIT_STATUS:-0}" | |
| function mycd_command_exists() { | |
| command -v "$1" >/dev/null 2>&1 | |
| } # end mycd_command_exists | |
| function mycd_is_zsh_shell() { | |
| [[ -n "${ZSH_VERSION-}" ]] || [[ "$0" == *"zsh" ]] | |
| } # end mycd_is_zsh_shell | |
| function mycd_is_bash_shell() { | |
| [[ -n "${BASH_VERSION-}" ]] || [[ "$0" == *"bash" ]] | |
| } # end mycd_is_bash_shell | |
| function mycd_history_builtin_available() { | |
| builtin history 1>/dev/null 2>/dev/null | |
| } # end mycd_history_builtin_available | |
| function mycd_can_manage_history() { | |
| mycd_is_interactive_shell || return 1 | |
| mycd_history_builtin_available || return 1 | |
| return 0 | |
| } # end mycd_can_manage_history | |
| function mycd_warn() { | |
| printf '%s\n' "$*" >&2 | |
| } # end mycd_warn | |
| ## DEBUG First Concept ( type_function_exists nvm_select_from_mycd ) && return | |
| function nvm_select_from_mycd(){ | |
| # local DEBUG=1 | |
| (( DEBUG )) && echo "debug nvm_select_from_mycd" | |
| [[ "$MYCD_ENABLE_VERSION_MANAGERS" == "1" ]] || return 0 | |
| type_function_exists nvm || return 0 | |
| mycd_command_exists node || return 0 | |
| if [ -f ".nvmrc" ] ; then # file exists | |
| { | |
| BASHSELECTINGNVMNODE=$(<.nvmrc) | |
| (( DEBUG )) && echo "# Current node responding is same as nvmrc then do nothing " | |
| if [[ "$(node --version)" == *"${BASHSELECTINGNVMNODE}"* ]] ; then | |
| { | |
| (( DEBUG )) && echo ".nvmrc found and ..node version is" | |
| (( DEBUG )) && node --version | |
| set -e | |
| set +e | |
| } | |
| else | |
| { | |
| (( DEBUG )) && echo ".nvmrc not found" | |
| (( DEBUG )) && echo "# Is node installed in nvm ?" | |
| if [[ "$(nvm ls | grep "${BASHSELECTINGNVMNODE}" | head -1)" == *"${BASHSELECTINGNVMNODE}"* ]] ; then | |
| { | |
| (( DEBUG )) && echo "nvm ls shows has node verison installed found" | |
| (( DEBUG )) && echo "tell to select it node version" | |
| nvm use "${BASHSELECTINGNVMNODE}" >/dev/null 2>&1; | |
| # Confirm | |
| if [[ "$(node --version)" == *"${BASHSELECTINGNVMNODE}"* ]] ; then | |
| { | |
| set -e | |
| set +e | |
| } | |
| else | |
| { | |
| echo "ERROR Mycd - Failed to select node - nvm use ${BASHSELECTINGNVMNODE}" | |
| } | |
| fi | |
| } | |
| else | |
| { | |
| if [[ "$MYCD_ALLOW_INSTALLS" != "1" ]] ; then | |
| { | |
| echo "INFO Mycd - Skipping nvm install for ${BASHSELECTINGNVMNODE}. Set MYCD_ALLOW_INSTALLS=1 to enable installs." | |
| return 0 | |
| } | |
| fi | |
| (( DEBUG )) && echo "not found" | |
| nvm install "${BASHSELECTINGNVMNODE}" >/dev/null 2>&1; | |
| wait | |
| # Do switch case again | |
| if [[ "$(nvm ls | grep "${BASHSELECTINGNVMNODE}" | head -1)" == *"${BASHSELECTINGNVMNODE}"* ]] ; then | |
| { | |
| (( DEBUG )) && echo "found" | |
| (( DEBUG )) && echo "select it" | |
| nvm use "${BASHSELECTINGNVMNODE}" >/dev/null 2>&1; | |
| # Confirm | |
| if [[ "$(node --version)" == *"${BASHSELECTINGNVMNODE}"* ]] ; then | |
| { | |
| set -e | |
| set +e | |
| } | |
| else | |
| { | |
| echo "ERROR Mycd - Failed to select node - nvm use ${BASHSELECTINGNVMNODE}" | |
| } | |
| fi | |
| } | |
| else | |
| { | |
| (( DEBUG )) && echo "Not installed" | |
| (( DEBUG )) && echo "not found" | |
| echo "ERROR Mycd - Failed to install node ${BASHSELECTINGNVMNODE} - nvm install ${BASHSELECTINGNVMNODE}" | |
| } | |
| fi | |
| } | |
| fi | |
| } | |
| fi | |
| } | |
| fi | |
| return 0 | |
| } # end nvm_select_from_mycd | |
| function nodenv_select_from_mycd(){ | |
| # local DEBUG=1 | |
| (( DEBUG )) && echo "debug nodenv_select_from_mycd" | |
| [[ "$MYCD_ENABLE_VERSION_MANAGERS" == "1" ]] || return 0 | |
| mycd_command_exists nodenv || return 0 | |
| mycd_command_exists node || return 0 | |
| if [ -f ".node-version" ] ; then # file exists | |
| { | |
| BASHSELECTINGNODENVNODE=$(<.node-version) | |
| (( DEBUG )) && echo "# Current node responding is same as ode-version then do nothing" | |
| if [[ "$(node --version)" == *"${BASHSELECTINGNODENVNODE}"* ]] ; then | |
| { | |
| (( DEBUG )) && echo "mycd nodenv found node" | |
| (( DEBUG )) && node --version | |
| set -e | |
| set +e | |
| } | |
| else | |
| { | |
| (( DEBUG )) && echo "mycd nodenv node not found" | |
| (( DEBUG )) && echo "# Is node installed in nodenv ?" | |
| if [[ "$(nodenv versions | grep "${BASHSELECTINGNODENVNODE}" | head -1)" == *"${BASHSELECTINGNODENVNODE}"* ]] ; then | |
| { | |
| (( DEBUG )) && echo "nodenv version found" | |
| (( DEBUG )) && echo "nodenv select it" | |
| nodenv local "${BASHSELECTINGNODENVNODE}" >/dev/null 2>&1; | |
| (( DEBUG )) && echo "# Confirm selection" | |
| local confirming="" | |
| confirming="$(~/.nodenv/shims/node --version)" | |
| (( DEBUG )) && echo "${confirming}" | |
| (( DEBUG )) && echo "${BASHSELECTINGNODENVNODE}" | |
| if [[ "${confirming}" == *"${BASHSELECTINGNODENVNODE}"* ]] ; then | |
| { | |
| set -e | |
| set +e | |
| } | |
| else | |
| { | |
| echo "ERROR Mycd 1 - Failed to select node ${confirming} != - nodenv local ${BASHSELECTINGNODENVNODE}" | |
| } | |
| fi | |
| } | |
| else | |
| { | |
| if [[ "$MYCD_ALLOW_INSTALLS" != "1" ]] ; then | |
| { | |
| echo "INFO Mycd - Skipping nodenv install for ${BASHSELECTINGNODENVNODE}. Set MYCD_ALLOW_INSTALLS=1 to enable installs." | |
| return 0 | |
| } | |
| fi | |
| (( DEBUG )) && echo "mycd nodenv node version # Not installed" | |
| (( DEBUG )) && echo "mycd nodenv node version not found" | |
| nodenv install "${BASHSELECTINGNODENVNODE}" >/dev/null 2>&1; | |
| wait | |
| (( DEBUG )) && echo "mycd nodenv # Do switch case again" | |
| if [[ "$(node versions | grep "${BASHSELECTINGNODENVNODE}" | head -1)" == *"${BASHSELECTINGNODENVNODE}"* ]] ; then | |
| { | |
| (( DEBUG )) && echo "mycd nodenv found again" | |
| (( DEBUG )) && echo "mycd nodenv select it again" | |
| nodenv local "${BASHSELECTINGNODENVNODE}" >/dev/null 2>&1; | |
| (( DEBUG )) && echo "# Confirm selection again" | |
| local confirming= | |
| confirming="$(~/.nodenv/shims/node --version)" | |
| (( DEBUG )) && echo "${confirming}" | |
| (( DEBUG )) && echo "${BASHSELECTINGNODENVNODE}" | |
| if [[ "${confirming}" == *"${BASHSELECTINGNODENVNODE}"* ]] ; then | |
| { | |
| set -e | |
| set +e | |
| } | |
| else | |
| { | |
| echo "ERROR Mycd 2 - Failed to select again node ${confirming} - nodenv local ${BASHSELECTINGNODENVNODE}" | |
| } | |
| fi | |
| } | |
| else | |
| { | |
| (( DEBUG )) && echo "Not installed" | |
| (( DEBUG )) && echo "not found" | |
| echo "ERROR Mycd - Failed to install node ${BASHSELECTINGNODENVNODE} - nodenv install ${BASHSELECTINGNODENVNODE}" | |
| } | |
| fi | |
| } | |
| fi | |
| } | |
| fi | |
| } | |
| fi | |
| return 0 | |
| } # end nodenv_select_from_mycd | |
| function rbenv_select_from_mycd(){ | |
| # local DEBUG=1 | |
| (( DEBUG )) && echo "debug rbenv_select_from_mycd" | |
| [[ "$MYCD_ENABLE_VERSION_MANAGERS" == "1" ]] || return 0 | |
| mycd_command_exists rbenv || return 0 | |
| mycd_command_exists ruby || return 0 | |
| if [ -f ".ruby-version" ] ; then # file exists | |
| { | |
| BASHSELECTINGRBENVRUBY=$(<.ruby-version) | |
| (( DEBUG )) && echo "# Current ruby responding is same as ode-version then do nothing" | |
| if [[ "$(ruby --version)" == *"${BASHSELECTINGRBENVRUBY}"* ]] ; then | |
| { | |
| (( DEBUG )) && echo "mycd rbenv found ruby" | |
| (( DEBUG )) && ruby --version | |
| set -e | |
| set +e | |
| } | |
| else | |
| { | |
| (( DEBUG )) && echo "mycd rbenv ruby not found" | |
| (( DEBUG )) && echo "# Is ruby installed in rbenv ?" | |
| if [[ "$(rbenv versions | grep "${BASHSELECTINGRBENVRUBY}" | head -1)" == *"${BASHSELECTINGRBENVRUBY}"* ]] ; then | |
| { | |
| (( DEBUG )) && echo "rbenv version found" | |
| (( DEBUG )) && echo "rbenv select it" | |
| rbenv local "${BASHSELECTINGRBENVRUBY}" | |
| (( DEBUG )) && echo "# Confirm selection" | |
| local confirming="" | |
| confirming="$(~/.rbenv/shims/ruby --version)" | |
| (( DEBUG )) && echo "${confirming}" | |
| (( DEBUG )) && echo "${BASHSELECTINGRBENVRUBY}" | |
| if [[ "${confirming}" == *"${BASHSELECTINGRBENVRUBY}"* ]] ; then | |
| { | |
| set -e | |
| set +e | |
| } | |
| else | |
| { | |
| echo "ERROR Mycd 1 - Failed to select ruby ${confirming} != - rbenv local ${BASHSELECTINGRBENVRUBY}" | |
| } | |
| fi | |
| } | |
| else | |
| { | |
| if [[ "$MYCD_ALLOW_INSTALLS" != "1" ]] ; then | |
| { | |
| echo "INFO Mycd - Skipping rbenv install for ${BASHSELECTINGRBENVRUBY}. Set MYCD_ALLOW_INSTALLS=1 to enable installs." | |
| return 0 | |
| } | |
| fi | |
| (( DEBUG )) && echo "mycd rbenv ruby version # Not installed" | |
| (( DEBUG )) && echo "mycd rbenv ruby version not found" | |
| rbenv install "${BASHSELECTINGRBENVRUBY}" >/dev/null 2>&1; | |
| wait | |
| (( DEBUG )) && echo "mycd rbenv # Do switch case again" | |
| if [[ "$(ruby versions | grep "${BASHSELECTINGRBENVRUBY}" | head -1)" == *"${BASHSELECTINGRBENVRUBY}"* ]] ; then | |
| { | |
| (( DEBUG )) && echo "mycd rbenv found again" | |
| (( DEBUG )) && echo "mycd rbenv select it again" | |
| rbenv local "${BASHSELECTINGRBENVRUBY}" >/dev/null 2>&1; | |
| (( DEBUG )) && echo "# Confirm selection again" | |
| local confirming="" | |
| confirming="$(~/.rbenv/shims/ruby --version)" | |
| (( DEBUG )) && echo "${confirming}" | |
| (( DEBUG )) && echo "${BASHSELECTINGRBENVRUBY}" | |
| if [[ "${confirming}" == *"${BASHSELECTINGRBENVRUBY}"* ]] ; then | |
| { | |
| set -e | |
| set +e | |
| } | |
| else | |
| { | |
| echo "ERROR Mycd 2 - Failed to select again ruby ${confirming} - rbenv local ${BASHSELECTINGRBENVRUBY}" | |
| } | |
| fi | |
| } | |
| else | |
| { | |
| (( DEBUG )) && echo "Not installed" | |
| (( DEBUG )) && echo "not found" | |
| echo "ERROR Mycd - Failed to install ruby ${BASHSELECTINGRBENVRUBY} - rbenv install ${BASHSELECTINGRBENVRUBY}" | |
| } | |
| fi | |
| } | |
| fi | |
| } | |
| fi | |
| } | |
| fi | |
| return 0 | |
| } # end rbenv_select_from_mycd | |
| function execute_files_mycd(){ | |
| [[ "$MYCD_ENABLE_AUTOEXEC" == "1" ]] || return 0 | |
| if [ -f ".execute.sh" ] ; then # file exists | |
| { | |
| chmod +x .execute.sh 2>/dev/null || true | |
| sh .execute.sh >/dev/null 2>&1 || mycd_warn "INFO Mycd - Skipped .execute.sh because execution failed." | |
| } | |
| fi | |
| if [ -f ".execute.bash" ] ; then # file exists | |
| { | |
| chmod +x .execute.bash 2>/dev/null || true | |
| bash .execute.bash >/dev/null 2>&1 || mycd_warn "INFO Mycd - Skipped .execute.bash because execution failed." | |
| } | |
| fi | |
| if [ -f ".execute.zsh" ] ; then # file exists | |
| { | |
| if mycd_is_zsh_shell ; then | |
| { | |
| chmod +x .execute.zsh 2>/dev/null || true | |
| zsh .execute.zsh >/dev/null 2>&1 || mycd_warn "INFO Mycd - Skipped .execute.zsh because execution failed." | |
| } | |
| fi | |
| } | |
| fi | |
| if [ -f ".execute" ] ; then # file exists | |
| { | |
| chmod +x ./.execute 2>/dev/null || true | |
| ./.execute >/dev/null 2>&1 || mycd_warn "INFO Mycd - Skipped .execute because execution failed." | |
| } | |
| fi | |
| if [ -f ".autoexecute" ] ; then # file exists | |
| { | |
| chmod +x ./.autoexecute 2>/dev/null || true | |
| ./.autoexecute >/dev/null 2>&1 || mycd_warn "INFO Mycd - Skipped .autoexecute because execution failed." | |
| } | |
| fi | |
| return 0 | |
| } # end execute_files_mycd | |
| function git_projectparticipation_mycd(){ | |
| [[ "$MYCD_ENABLE_GIT_STATUS" == "1" ]] || return 0 | |
| if [ -d "$PWD/.git" ] ; then # dir exists | |
| { | |
| if command -v projectparticipation >/dev/null 2>&1; then #Command Exists | |
| { | |
| projectparticipation | |
| } | |
| fi | |
| if command -v gsb >/dev/null 2>&1; then #Command Exists | |
| { | |
| echo -e "\\033[38;5;93m === Git Status \\033[38;5;93m === \\033[38;5;123m "; | |
| gsb | |
| } | |
| fi | |
| } | |
| fi | |
| } # end git_projectparticipation_mycd | |
| export MYCD_HISTORY_FILENAME="${MYCD_HISTORY_FILENAME:-.dir_bash_history}" | |
| export MYCD_TUTORIAL_HISTORY_FILENAME="${MYCD_TUTORIAL_HISTORY_FILENAME:-.tutorial}" | |
| function mycd_history_target_for_dir(){ | |
| local dir="${1:-$PWD}" | |
| if [[ -f "$dir/$MYCD_TUTORIAL_HISTORY_FILENAME" && -w "$dir" ]] ; then | |
| { | |
| printf '%s\n' "$dir/$MYCD_TUTORIAL_HISTORY_FILENAME" | |
| return 0 | |
| } | |
| fi | |
| if [[ -w "$dir" ]] ; then | |
| { | |
| printf '%s\n' "$dir/$MYCD_HISTORY_FILENAME" | |
| } | |
| else | |
| { | |
| printf '%s\n' "$HOME/.bash_history" | |
| } | |
| fi | |
| } # end mycd_history_target_for_dir | |
| function mycd_history_ensure_file(){ | |
| local histfile="${1:-}" | |
| [[ -n "$histfile" ]] || return 1 | |
| touch "$histfile" 2>/dev/null || return 1 | |
| if [[ "$histfile" != "$HOME/.bash_history" ]] ; then | |
| { | |
| chmod 600 "$histfile" 2>/dev/null || true | |
| } | |
| fi | |
| } # end mycd_history_ensure_file | |
| function mycd_history_write_marker(){ | |
| local histfile="${1:-}" | |
| local message="${2:-}" | |
| [[ -n "$histfile" ]] || return 0 | |
| [[ -n "$message" ]] || return 0 | |
| mycd_can_manage_history || return 0 | |
| printf '#%s\n%s\n' "$(date +%s)" "$message" >> "$histfile" 2>/dev/null || true | |
| } # end mycd_history_write_marker | |
| function mycd_history_reload_current_file(){ | |
| local histfile="${1:-$HISTFILE}" | |
| mycd_history_ensure_file "$histfile" || return 1 | |
| export HISTFILE="$histfile" | |
| mycd_can_manage_history || return 0 | |
| history -c | |
| history -r "$HISTFILE" 2>/dev/null || history -r 2>/dev/null || true | |
| } # end mycd_history_reload_current_file | |
| function mycd_history_prompt_sync(){ | |
| local target_histfile="" | |
| mycd_can_manage_history || return 0 | |
| target_histfile="$(mycd_history_target_for_dir "$PWD")" || return 0 | |
| mycd_history_ensure_file "$target_histfile" || return 0 | |
| if [[ "${HISTFILE-}" == "$target_histfile" ]] ; then | |
| { | |
| history -a 2>/dev/null || true | |
| history -n 2>/dev/null || true | |
| return 0 | |
| } | |
| fi | |
| history -a 2>/dev/null || true | |
| export HISTFILE="$target_histfile" | |
| history -n 2>/dev/null || history -r "$HISTFILE" 2>/dev/null || history -r 2>/dev/null || true | |
| } # end mycd_history_prompt_sync | |
| function mycd_install_prompt_hook(){ | |
| local hook_name="mycd_history_prompt_sync" | |
| local legacy_hook="history -a; history -c; history -r;" | |
| mycd_is_bash_shell || mycd_is_zsh_shell || return 0 | |
| [[ -n "${PROMPT_COMMAND+x}" ]] || PROMPT_COMMAND="" | |
| while [[ "$PROMPT_COMMAND" == *"$legacy_hook"* ]] ; do | |
| { | |
| PROMPT_COMMAND="${PROMPT_COMMAND/$legacy_hook/}" | |
| PROMPT_COMMAND="${PROMPT_COMMAND/ / }" | |
| PROMPT_COMMAND="${PROMPT_COMMAND#; }" | |
| PROMPT_COMMAND="${PROMPT_COMMAND# }" | |
| } | |
| done | |
| case ";$PROMPT_COMMAND;" in | |
| *";$hook_name;"*) | |
| ;; | |
| *) | |
| if [[ -n "$PROMPT_COMMAND" ]] ; then | |
| { | |
| PROMPT_COMMAND="$hook_name; $PROMPT_COMMAND" | |
| } | |
| else | |
| { | |
| PROMPT_COMMAND="$hook_name" | |
| } | |
| fi | |
| ;; | |
| esac | |
| export PROMPT_COMMAND | |
| } # end mycd_install_prompt_hook | |
| function mycd_apply_directory_context(){ | |
| mycd_decide_nvm_or_nodenv | |
| rbenv_select_from_mycd | |
| execute_files_mycd | |
| git_projectparticipation_mycd | |
| } # end mycd_apply_directory_context | |
| function mycd() | |
| { | |
| local old_dir="$PWD" | |
| local old_histfile="$HISTFILE" | |
| local next_histfile="" | |
| mycd_can_manage_history && history -a 2>/dev/null || true | |
| mycd_history_write_marker "$old_histfile" "$USER has exited $old_dir for ${*-}" | |
| builtin cd "$@" # do actual cd | |
| next_histfile="$(mycd_history_target_for_dir "$PWD")" || return 1 | |
| if mycd_history_ensure_file "$next_histfile" ; then | |
| { | |
| export HISTFILE="$next_histfile" | |
| } | |
| else | |
| { | |
| export HISTFILE="$HOME/.bash_history" | |
| mycd_history_ensure_file "$HISTFILE" || true | |
| } | |
| fi | |
| mycd_history_write_marker "$HISTFILE" "$USER has entered $PWD from $old_dir" | |
| mycd_apply_directory_context | |
| } # end mycd | |
| alias cd="mycd" | |
| function mycd_decide_nvm_or_nodenv(){ | |
| local flag=0 | |
| ( type_function_exists nvm ) && flag=$(( flag + 1 )) | |
| ( type_function_exists nodenv ) && flag=$(( flag + 3 )) | |
| if (( flag == 4 )) ; then | |
| { | |
| echo "ERROR Two Node version managers found active nvm and nodenv. Consider removing one. Using nodenv now. " | |
| nodenv_select_from_mycd | |
| } | |
| elif (( flag == 1 )) ; then | |
| { | |
| nvm_select_from_mycd | |
| } | |
| elif (( flag == 3 )) ; then | |
| { | |
| nodenv_select_from_mycd | |
| } | |
| else | |
| { | |
| return 0 | |
| } | |
| fi | |
| } # end mycd_decide_nvm_or_nodenv | |
| # initial shell opened | |
| export HISTFILE="$(mycd_history_target_for_dir "$PWD")" | |
| mycd_history_reload_current_file "$HISTFILE" | |
| # timestamp all history entries | |
| export HISTTIMEFORMAT="%h/%d - %H:%M:%S " | |
| export HISTCONTROL=ignoredups:erasedups | |
| export HISTSIZE=1000000 | |
| export HISTFILESIZE=1000000 | |
| if mycd_is_zsh_shell ; then | |
| { | |
| setopt append_history ## append, no clearouts | |
| setopt hist_verify ## edit a recalled history line before executing | |
| setopt completeinword | |
| setopt interactive | |
| setopt share_history ## Share history between multiple simultaneous zsh sessions. | |
| setopt inc_append_history | |
| } | |
| elif mycd_is_bash_shell ; then | |
| { | |
| shopt -s histappend ## append, no clearouts | |
| shopt -s histverify ## edit a recalled history line before executing | |
| shopt -s histreedit ## reedit a history substitution line if it failed | |
| } | |
| fi | |
| mycd_apply_directory_context | |
| mycd_install_prompt_hook | |
| # } | |
| # else | |
| # { | |
| # echo "skip repeats"; | |
| } | |
| fi | |
| # } | |
| # else | |
| # { | |
| # echo doble hola | |
| # _mycd_no_wall_broadcast_no_banner=1 | |
| # _mycd_cron_running=0 | |
| # exec 3>&1 1>>"${_log_file}" 2>&1 # How to write output to both console and file REF: https:/> | |
| # exec 3>&1 4>&2 >>"${_log_file}" 2>&1 # How to redirect output REF: https://stackoverflow.co> | |
| # } | |
| # fi |
Author
Author
updated to use echo $0 instead of which shell to check for the current executing shell
Author
added looking into .nvmrc file and changing the node version to match.
Author
added using nvm or nodenv to select version of node when doing cd into project with a .node-version or a .nvmrc file.
Author
added selecting ruby version with rbenv when cd into folder
Author
Added update to be more robust for bash zsh and better non obtrusive logic
Author
updated performance issues and added tty detection to avoid hangs in subprocesses
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
History Directory Based Bash Histories For Linux, Mac, Bash, Shell, and Zsh ( tutorial, dir_bash_history, autoexecute, and execute); self-executing files inside a folder.
Rationale
Using a directory-based bash history allows for a record of shell actions on a directory basis, so a group of developers has some record of what was done while in a directory, when, and by whom. This can be helpful when trying to reconstruct history with limited documentation.
This was derived from http://dieter.plaetinck.be/per_directory_bash_history
Installation
Add to MAC Bash:
Add to Linux Bash:
Add to Zsh:
Add .dir_bash_history to .gitignore in your work folder
Remember to open a new tab or reopen the terminal for this to work.
Usage
This works while using the terminal, like Gnome-Terminal. Since it is attaching its functionality to the "cd" command,
YOU MUST USE "cd" in order for this technique TO WORK.
This script provides three functions:
Stores local history inside a local file in each directory: .dir_bash_history
Record local history inside a local file as tutorial instead: .tutorial
( for this to work, you have to create the file .tutorial )
( by doing this, it will stop writting .dir_bash_history and only to .tutorial file )
Executes a local file inside a folder when it exists called: .execute, .execute.sh, .execute.bash, or .autoexecute
( for this to work, you have to create the file and place your desired executions here )
:)