Skip to content

Instantly share code, notes, and snippets.

@vidbina
Created March 4, 2016 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vidbina/70cb7846433602b67aaf to your computer and use it in GitHub Desktop.
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.
#!/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