startenv for gnome-terminal
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/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