diff --git a/etc/bash_profile b/etc/profile similarity index 75% rename from etc/bash_profile rename to etc/profile index f429540..c8d763a 100644 --- a/etc/bash_profile +++ b/etc/profile @@ -4,8 +4,9 @@ ##### loads gotomark preferences if file exists ##### # # if [ -f ~/.gotomark/profile.sh ]; then # - source ~/.gotomark/profile.sh # - fi # + source ~/.gotomark/profile.sh # + export GOTOMARK=INSTALLED # + fi # # # ##################################################### ###### https://github.com/whtevn/gotomark ########### diff --git a/etc/profile_installer b/etc/profile_installer new file mode 100755 index 0000000..6d92468 --- /dev/null +++ b/etc/profile_installer @@ -0,0 +1,29 @@ + +################## added by gotomark ################ +# # +###### attaches goto command to dogoto printer ###### +# # + function __goto { # + local loc=`dogoto "$@"` # + if [ -d "$loc" ]; then # + cd $loc # + fi # + # + if [ -f "$loc" ]; then # + $EDITOR $loc # + fi # + } # + alias goto=__goto # +# # +########## bash completion for goto command ######### +# # + function _goto { # + local cur=${COMP_WORDS[COMP_CWORD]} # + local opts=`dogoto -m` # + COMPREPLY=( $(compgen -W "$opts" -- $cur) ) # + } # + complete -F _goto goto # +# # +##################################################### +###### https://github.com/whtevn/gotomark ########### +##################################################### diff --git a/etc/profile_update b/etc/profile_update deleted file mode 100755 index 291a7f3..0000000 --- a/etc/profile_update +++ /dev/null @@ -1,29 +0,0 @@ - -################## added by gotomark ################ -# # -###### attaches goto command to dogoto printer ###### -# # - function __goto { # - local loc=`dogoto "$@"` # - if [ -d "$loc" ]; then # - cd $loc # - fi # - # - if [ -f "$loc" ]; then # - $EDITOR $loc # - fi # - } # - alias goto=__goto # -# # -########## bash completion for goto command ######### -# # - function _goto { # - local cur=${COMP_WORDS[COMP_CWORD]} # - local opts=`dogoto -m` # - COMPREPLY=( $(compgen -W "$opts" -- $cur) ) # - } # - complete -F _goto goto # -# # -##################################################### -###### https://github.com/whtevn/gotomark ########### -##################################################### diff --git a/install.js b/install.js index 113f264..7d59757 100755 --- a/install.js +++ b/install.js @@ -1,35 +1,55 @@ #!/usr/bin/env node var fs = require('fs'); +var readline = require('readline'); +var rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); var homedir = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; -var profile=homedir+"/.bash_profile"; -var profile_update='./etc/bash_profile'; -var installer='./etc/profile_update'; -var markdir = homedir+"/.gotomark"; -var uid, gid; +var profile_add='./etc/profile'; +var installer='./etc/profile_installer'; +var markdir = homedir+"/.gotomark"; +var profile_loc = markdir + "/profile_loc" +var uid, gid, profile; -fs.mkdir(markdir, function(e){ - copyFile(installer, markdir+"/profile.sh", function(){ - fs.readFile(profile_update, {encoding: 'utf8'}, function(err, data){ - fs.createWriteStream(profile, {'flags': 'a'}).write(data, 'utf8', function(err, data){ - uid = process.env.SUDO_UID || process.getuid() - gid = process.env.SUDO_GID || process.getgid() - fs.chownSync(markdir, +(uid), +(gid)); - fs.chownSync(markdir+"/profile.sh", +(uid), +(gid)); - fs.exists(homedir+"/.marked_destinations", function(exists){ - if(exists){ - fs.rename(homedir+"/.marked_destinations", markdir+"/marked_destinations"); +rl.question("What is your shell's profile called? (default: .bash_profile)\n", function(answer){ + profile = answer || ".bash_profile"; + profile = homedir+"/"+profile; + console.log("Using profile at " + profile); + fs.mkdir(markdir, function(e){ + fs.createWriteStream(profile_loc, {'flags': 'a'}).write(profile, 'utf8', function(err, data){ + if(err) throw(err); + copyFile(installer, markdir+"/profile.sh", function(){ + fs.readFile(profile_add, {encoding: 'utf8'}, function(err, data){ + if (process.env.GOTOMARK !== "INSTALLED") { + fs.createWriteStream(profile, {'flags': 'a'}).write(data, 'utf8', function(err, data){ + uid = process.env.SUDO_UID || process.getuid() + gid = process.env.SUDO_GID || process.getgid() + fs.chownSync(markdir, +(uid), +(gid)); + fs.chownSync(markdir+"/profile.sh", +(uid), +(gid)); + fs.exists(homedir+"/.marked_destinations", function(exists){ + if(exists){ + fs.rename(homedir+"/.marked_destinations", markdir+"/marked_destinations"); + } + }); + if(err) throw(err); + console.log("\n#######################################\n#"); + console.log("# Installation Success, I presume\n#"); + console.log("# Now Run this command:"); + console.log("# \tsource " + profile); + console.log("#\n#######################################\n"); + }); + } else { + console.log("\n#######################################\n#"); + console.log("# Already installed!"); + console.log("#\n#######################################\n"); } }); - if(err) throw(err); - console.log("\n#######################################\n#"); - console.log("# Installation Success, I presume\n#"); - console.log("# Now Run this command:"); - console.log("# \tsource ~/.bash_profile"); - console.log("#\n#######################################\n"); }); }); }); + rl.close(); }); function copyFile(source, target, cb) { diff --git a/uninstall.js b/uninstall.js index 41e7a04..e2e9269 100755 --- a/uninstall.js +++ b/uninstall.js @@ -2,10 +2,10 @@ var fs = require('fs'); var homedir = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; -var profile=homedir+"/.bash_profile"; -var profile_update='./etc/bash_profile'; -var installer='./etc/profile_update'; -var markdir = homedir+"/.gotomark"; +var profile_add='./etc/profile'; +var installer='./etc/profile_installer'; +var markdir = homedir+"/.gotomark"; +var profile_loc=markdir+"/profile_loc" /* fs.exists(markdir, function (exists) { @@ -18,15 +18,21 @@ fs.exists(markdir, function (exists) { } }); */ +fs.readFile(profile_loc, 'utf8', function (err, data) { + var profile = data; + console.log(data); + fs.readFile(profile, 'utf8', function (err,data) { + if (err) { + return console.log(err); + } -fs.readFile(profile, 'utf8', function (err,data) { - if (err) { - return console.log(err); - } - - var result = data.replace(/(^\s*$\s)+#* added by gotomark #*$\s(^.*$\s)*^#*\shttps:.*gotomark\s#*$\s#*\s/mg, ''); - fs.writeFile(profile, result, 'utf8', function (err) { - if (err) return console.log(err); + var result = data.replace(/(^\s*$\s)+#* added by gotomark #*$\s(^.*$\s)*^#*\shttps:.*gotomark\s#*$\s#*\s/mg, ''); + fs.writeFile(profile, result, 'utf8', function (err) { + if (err) return console.log(err); + console.log("\n#######################################\n#"); + console.log("# Please run \"export GOTOMARK=\" to reinstall in this shell"); + console.log("#\n#######################################\n"); + }); }); }); // http://stackoverflow.com/questions/14177087/replace-a-string-in-a-file-with-nodejs