Last active
          October 29, 2025 10:08 
        
      - 
      
 - 
        
Save coderofsalvation/b5427058b7e5595709082fa4996bcfea to your computer and use it in GitHub Desktop.  
  
    
      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
    
  
  
    
  | # | |
| # autoenv alias for 'cd' (basically conda/nix-shell/virtual-env triggered by cd) | |
| # | |
| # usage: put this in your .bashrc and see magic happening when 'cd'-ing to directories | |
| # | |
| cd(){ | |
| if [[ ! "$(readlink -f "$1")" =~ ^"$(pwd)" ]]; then # if not cd'ing to a subdir | |
| test -f .env.leave && source .env.leave # cleanup environment | |
| fi | |
| # try running original 'cd' command | |
| builtin cd ${1:+"$@"} && { | |
| # show [xattr] attributes if any | |
| getfattr -d . 2>/dev/null | awk 'NR > 1 { print $0 }' | |
| # run autoenv (setup environment via .env) | |
| env=$(pwd)/.env | |
| test -f $env && source $env | |
| # run python virtual-env | |
| test -d venv && source venv/bin/activate | |
| # display available branches if any | |
| test -d .git && { | |
| echo "[git] remotes found:" | |
| git remote -v | grep fetch | awk '{ print "[git] * "$0 }' | |
| echo "" | |
| } | |
| # list directories | |
| [[ ! $(pwd) =~ "/mnt" ]] && ls | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment