-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prompt user for completion script installation method
- bashrc - zshrc - pkg-config bash-completion completionsdir - /usr/share/bash-completion/completions - pkg-config bash-completion compatdir - /etc/bash_completion.d Asks pkg-config for bash-completion variable, otherwise asks only for bashrc or zshrc
- Loading branch information
Showing
8 changed files
with
197 additions
and
69 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
*.swp | ||
src | ||
docs | ||
.tern-port |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
test: babel | ||
mocha test/ -R min | ||
mocha test/ -R spec | ||
|
||
babel: | ||
babel lib/ -d src/ | ||
babel lib/ -d src/ | ||
|
||
lint: | ||
eslint . --env es6 | ||
eslint . --env es6 | ||
|
||
docs: | ||
tomdox lib/complete.js lib/debug.js lib/index.js lib/commands/*.js --primary orange --accent deep_orange --icon keyboard_tab --prefix https://mklabs.github.io/node-tabtab/ | ||
tomdox lib/complete.js lib/debug.js lib/index.js lib/commands/*.js --primary orange --accent deep_orange --icon keyboard_tab --prefix https://mklabs.github.io/node-tabtab/ | ||
|
||
ghpages: | ||
bake docs && git co gh-pages && git rm -r . && cp -r docs/* . && git add . && git ci | ||
bake docs && git co gh-pages && git rm -r . && cp -r docs/* . && git add . && git ci | ||
|
||
env: | ||
@echo $(PATH) | ||
@echo $(PATH) | ||
|
||
build: test lint | ||
build: test | ||
|
||
tt: | ||
COMP_LINE="list --foo" COMP_CWORD=2 COMP_POINT=4 tabtab completion | ||
COMP_LINE="list --foo" COMP_CWORD=2 COMP_POINT=4 tabtab completion | ||
|
||
watch: | ||
watchd lib/**/* test/**/* bin/* -c 'bake build' | ||
watchd lib/*.js lib/**/* test/**/* bin/* -c 'bake build' | ||
|
||
all: build watch |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
const debug = require('./debug')('tabtab:installer') | ||
|
||
|
||
import path from 'path' | ||
import inquirer from 'inquirer'; | ||
import { spawn, exec } from 'child_process'; | ||
|
||
// Public: Manage installation / setup of completion scripts. | ||
// | ||
// pkg-config --variable=completionsdir bash-completion | ||
// pkg-config --variable=compatdir bash-completion | ||
export default class Installer { | ||
constructor(options) { | ||
this.options = options || {}; | ||
debug('init', this.options); | ||
} | ||
|
||
// Called on install command. | ||
// | ||
// Performs the installation process. | ||
handle(name) { | ||
debug('handle', name); | ||
this.options.name = name; | ||
|
||
return this.prompt() | ||
.then(this.writeTo.bind(this)); | ||
} | ||
|
||
writeTo(data) { | ||
var destination = data.destination; | ||
debug('Installing completion script to %s directory', destination); | ||
|
||
if (destination === 'bashrc') destination = path.join(this.home, '.bashrc'); | ||
else if (destination === 'zshrc') destination = path.join(this.home, '.zshrc'); | ||
else destination = path.join(destination, this.options.name); | ||
|
||
debug('Installing completion script to %s directory', destination); | ||
|
||
} | ||
|
||
get home() { | ||
return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']; | ||
} | ||
|
||
// Prompts user for installation location. | ||
prompt() { | ||
var choices = [{ | ||
name: '~/.bashrc', | ||
value: 'bashrc', | ||
short: 'bash' | ||
}, { | ||
name: '~/.zshrc', | ||
value: 'zshrc', | ||
short: 'zsh' | ||
}]; | ||
|
||
var prompts = [{ | ||
message: 'Where do you want to setup the completion script', | ||
name: 'destination', | ||
type: 'list', | ||
choices: choices | ||
}]; | ||
|
||
return this.completionsdir() | ||
.then((dir) => { | ||
if (dir) { | ||
choices.push({ | ||
name: dir, | ||
value: dir, | ||
}); | ||
} | ||
|
||
return this.compatdir(); | ||
}) | ||
.then((dir) => { | ||
if (dir) { | ||
choices.push({ | ||
name: dir, | ||
value: dir | ||
}); | ||
} | ||
|
||
return this.ask(prompts); | ||
}); | ||
} | ||
|
||
ask(prompts) { | ||
debug('Ask', prompts); | ||
return inquirer.prompt(prompts); | ||
} | ||
|
||
// Public: pkg-config wrapper | ||
pkgconfig(variable) { | ||
return new Promise((r, errback) => { | ||
var cmd = `pkg-config --variable=${variable} bash-completion`; | ||
exec(cmd, function(err, stdout, stderr) { | ||
if (err) return errback(err); | ||
stdout = stdout.trim(); | ||
debug('Got %s for %s', stdout, variable); | ||
r(stdout); | ||
}); | ||
}); | ||
} | ||
|
||
// Returns the pkg-config variable for "completionsdir" and bash-completion | ||
// command. | ||
completionsdir() { | ||
debug('Asking pkg-config for completionsdir'); | ||
return this.pkgconfig('completionsdir'); | ||
} | ||
|
||
// Returns the pkg-config variable for "compatdir" and bash-completion | ||
// command. | ||
compatdir() { | ||
debug('Asking pkg-config for compatdir'); | ||
return this.pkgconfig('compatdir'); | ||
} | ||
} |
Oops, something went wrong.