Skip to content

Instantly share code, notes, and snippets.

@dragonee
Last active March 5, 2019 23:16
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 dragonee/b6890faf31fc2a793280b1eac1f19390 to your computer and use it in GitHub Desktop.
Save dragonee/b6890faf31fc2a793280b1eac1f19390 to your computer and use it in GitHub Desktop.
startenv for gnome-terminal
#!/bin/bash
# stub implementation of https://github.com/dragonee/iterm2-startenv for gnome-terminal
# using bash and nodejs
# this code should be put at the end of your .bashrc
# usage:
# put https://github.com/dragonee/iterm2-startenv/blob/master/examples/fullexample.js
# as .startenv.js in your project root directory
# modify it to your needs
# add /.startenv/ pattern to your .gitignore
# only ALLTERMS and TERMS work
run_startenv_cmd() {
if [ ! -d .startenv ]; then
mkdir .startenv
fi
# check modified dates
if [ -f .startenv/term.$1.sh ] && [ .startenv/term.$1.sh -nt .startenv.js ]; then
return
fi
node <<EOF > .startenv/term.$1.sh
ALLTERMS = []
title = function(title) {
return 'echo -ne "\\\\033]0;' + title + '\\\\007"'
}
require("./.startenv.js");
for(i = 0; i < ALLTERMS.length; i++) {
console.log(ALLTERMS[i])
}
term_cmds = TERMS[$1]
if(!Array.isArray(term_cmds)) {
term_cmds = [term_cmds]
}
for(i = 0; i < term_cmds.length; i++) {
console.log(term_cmds[i])
}
EOF
}
startenv() {
if [ ! -f .startenv.js ]; then
echo "Error: no .startenv.js file is present"
return
fi
terms_count=$(node <<EOF
title = function(x) {
return x
}
config = require("./.startenv.js");
console.log(TERMS.length);
EOF
)
for ((i=0; i < terms_count; i++)); do
STARTENV_SHELL="$i" gnome-terminal --tab
done
}
if [ -n "$STARTENV_SHELL" ]; then
run_startenv_cmd "$STARTENV_SHELL"
cat .startenv/term."$STARTENV_SHELL".sh
. .startenv/term."$STARTENV_SHELL".sh
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment