Created
March 4, 2016 22:26
-
-
Save vidbina/70cb7846433602b67aaf to your computer and use it in GitHub Desktop.
Call `zap` in a terminal of interest. Go to another terminal and call `splat` to load all the environment variables as known in the terminal from which `zap` was called. Open another terminal and call `teleport` to go to the directory from which `zap` was called.
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
#!/bin/zsh | |
# Since I keep opening new windows and cd-ing into the right places or | |
# exporting the needed variables, I figured it would make a lot of sense | |
# to have some code do this for me... It's simply: zap, splat, teleport! | |
function zap() { | |
# make a snapshot of whatever matters at this moment :) | |
echo $PWD > "/tmp/zap.pwd" | |
echo "⚡️" | |
printenv > "/tmp/zap.env" | |
} | |
function splat() { | |
# splat your brains over the wall... all zapped env vars will be know here | |
if [[ -a "/tmp/zap.env" ]] { | |
echo "💥" | |
cat /tmp/zap.env | | |
sed '/^_=/d' | | |
sed 's/^/export /' | | |
sed 's/=/="/' | | |
sed 's/$/"/' > /tmp/zap.env.sh | |
source /tmp/zap.env.sh | |
} | |
} | |
function teleport() { | |
# travel to the zapped location | |
if [[ -a "/tmp/zap.pwd" ]] { | |
echo "🚪" | |
cd $(cat "/tmp/zap.pwd") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment