Skip to main content
deleted 5 characters in body
Source Link
ElTi-42
  • 101
  • 3

i realized this via direnv and a shell script what is called via an alias

~/folder_a/.envrc

export GO_TO_DIR="./subdir_a"

~/folder_b/.envrc

export GO_TO_DIR="~/another_dir"

my go_to.sh

#!/bin/sh
value="${GO_TO_DIR}"

if [ -z $value ]
then
  exit 0
fi

cd $value

don't forget to make this file executeable

chmod u+x /path/to/script/go_to.sh

now i've set an alias to this script in my ~/.bashrc and ~/.zshrc and it works

alias goto="sh /path/to/script/go_to.sh"

bonus:

  1. i can sat a global env to change to a standard destination until it is overwritten with the directory specific env

  2. if no env is defined, nothing will happen

__

a second way to execute thewithout a script is to change the alias directly test if the env exists

alias goto='sh -c "if [ ! -z ${GO_TO_DIR} ]; then cd ${GO_TO_DIR}; fi;"'

i realized this via direnv and a shell script what is called via an alias

~/folder_a/.envrc

export GO_TO_DIR="./subdir_a"

~/folder_b/.envrc

export GO_TO_DIR="~/another_dir"

my go_to.sh

#!/bin/sh
value="${GO_TO_DIR}"

if [ -z $value ]
then
  exit 0
fi

cd $value

don't forget to make this file executeable

chmod u+x /path/to/script/go_to.sh

now i've set an alias to this script in my ~/.bashrc and ~/.zshrc and it works

alias goto="sh /path/to/script/go_to.sh"

bonus:

  1. i can sat a global env to change to a standard destination until it is overwritten with the directory specific env

  2. if no env is defined, nothing will happen

__

a second way to execute the script is to change the alias directly test if the env exists

alias goto='sh -c "if [ ! -z ${GO_TO_DIR} ]; then cd ${GO_TO_DIR}; fi;"'

i realized this via direnv and a shell script what is called via an alias

~/folder_a/.envrc

export GO_TO_DIR="./subdir_a"

~/folder_b/.envrc

export GO_TO_DIR="~/another_dir"

my go_to.sh

#!/bin/sh
value="${GO_TO_DIR}"

if [ -z $value ]
then
  exit 0
fi

cd $value

don't forget to make this file executeable

chmod u+x /path/to/script/go_to.sh

now i've set an alias to this script in my ~/.bashrc and ~/.zshrc and it works

alias goto="sh /path/to/script/go_to.sh"

bonus:

  1. i can sat a global env to change to a standard destination until it is overwritten with the directory specific env

  2. if no env is defined, nothing will happen

__

a second way without a script is to change the alias directly test if the env exists

alias goto='sh -c "if [ ! -z ${GO_TO_DIR} ]; then cd ${GO_TO_DIR}; fi;"'
deleted 2 characters in body
Source Link
ElTi-42
  • 101
  • 3

i realized this via direnv and a shell script what is called via an alias

~/folder_a/.envrc

export GO_TO_DIR="./subdir_a"

~/folder_b/.envrc

export GO_TO_DIR="~/another_dir"

my go_to.sh

#!/bin/sh
value="${GO_TO_DIR}"

if [ ! -z $value ]
then
  exit 0
fi

cd $value

don't forget to make this file executeable

chmod u+x /path/to/script/go_to.sh

now i've set an alias to this script in my ~/.bashrc and ~/.zshrc and it works

alias goto="sh /path/to/script/go_to.sh"

bonus:

  1. i can sat a global env to change to a standard destination until it is overwritten with the directory specific env

  2. if no env is defined, nothing will happen

__

a second way to execute the script is to change the alias directly test if the env exists

alias goto='sh -c "if [ ! -z ${GO_TO_DIR} ]; then cd ${GO_TO_DIR}; fi;"'

i realized this via direnv and a shell script what is called via an alias

~/folder_a/.envrc

export GO_TO_DIR="./subdir_a"

~/folder_b/.envrc

export GO_TO_DIR="~/another_dir"

my go_to.sh

#!/bin/sh
value="${GO_TO_DIR}"

if [ ! -z $value ]
then
  exit 0
fi

cd $value

don't forget to make this file executeable

chmod u+x /path/to/script/go_to.sh

now i've set an alias to this script in my ~/.bashrc and ~/.zshrc and it works

alias goto="sh /path/to/script/go_to.sh"

bonus:

  1. i can sat a global env to change to a standard destination until it is overwritten with the directory specific env

  2. if no env is defined, nothing will happen

__

a second way to execute the script is to change the alias directly test if the env exists

alias goto='sh -c "if [ ! -z ${GO_TO_DIR} ]; then cd ${GO_TO_DIR}; fi;"'

i realized this via direnv and a shell script what is called via an alias

~/folder_a/.envrc

export GO_TO_DIR="./subdir_a"

~/folder_b/.envrc

export GO_TO_DIR="~/another_dir"

my go_to.sh

#!/bin/sh
value="${GO_TO_DIR}"

if [ -z $value ]
then
  exit 0
fi

cd $value

don't forget to make this file executeable

chmod u+x /path/to/script/go_to.sh

now i've set an alias to this script in my ~/.bashrc and ~/.zshrc and it works

alias goto="sh /path/to/script/go_to.sh"

bonus:

  1. i can sat a global env to change to a standard destination until it is overwritten with the directory specific env

  2. if no env is defined, nothing will happen

__

a second way to execute the script is to change the alias directly test if the env exists

alias goto='sh -c "if [ ! -z ${GO_TO_DIR} ]; then cd ${GO_TO_DIR}; fi;"'
Source Link
ElTi-42
  • 101
  • 3

i realized this via direnv and a shell script what is called via an alias

~/folder_a/.envrc

export GO_TO_DIR="./subdir_a"

~/folder_b/.envrc

export GO_TO_DIR="~/another_dir"

my go_to.sh

#!/bin/sh
value="${GO_TO_DIR}"

if [ ! -z $value ]
then
  exit 0
fi

cd $value

don't forget to make this file executeable

chmod u+x /path/to/script/go_to.sh

now i've set an alias to this script in my ~/.bashrc and ~/.zshrc and it works

alias goto="sh /path/to/script/go_to.sh"

bonus:

  1. i can sat a global env to change to a standard destination until it is overwritten with the directory specific env

  2. if no env is defined, nothing will happen

__

a second way to execute the script is to change the alias directly test if the env exists

alias goto='sh -c "if [ ! -z ${GO_TO_DIR} ]; then cd ${GO_TO_DIR}; fi;"'