Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit d635755ca6fefd8b1bb5311b307c21f8e3ff200d @deefour committed Nov 15, 2012
Showing with 1,409 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +7 −0 .travis.yml
  3. +3 −0 AUTHORS
  4. +20 −0 LICENSE
  5. +166 −0 README.md
  6. +115 −0 app.js
  7. +16 −0 assets/functions
  8. +4 −0 bin/speed-dial
  9. +12 −0 lib/cli.js
  10. +91 −0 lib/commands/add.js
  11. +56 −0 lib/commands/addlisting.js
  12. +223 −0 lib/commands/go.js
  13. +36 −0 lib/commands/group.js
  14. +71 −0 lib/commands/init.js
  15. +144 −0 lib/commands/list.js
  16. +118 −0 lib/commands/remove.js
  17. +10 −0 lib/commands/version.js
  18. +114 −0 lib/storage.js
  19. +147 −0 lib/support.js
  20. +54 −0 package.json
@@ -0,0 +1,2 @@
+*-config.json
+node_modules
@@ -0,0 +1,7 @@
+language: node_js
+node_js:
+ - 0.6
+ - 0.8
+branches:
+ only:
+ - master
@@ -0,0 +1,3 @@
+Authors ordered by first contribution
+
+Jason Daly <jason@deefour.me> (http://deefour.me)
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Jason Daly <jason@deefour.me>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
166 README.md
@@ -0,0 +1,166 @@
+# SpeedDial
+
+[![Build Status](https://secure.travis-ci.org/deefour/SpeedDial.png)](http://travis-ci.org/deefour/SpeedDial)
+
+(c) 2012 Jason Daly <jason@deefour.me> (http://deefour.me)
+
+Released under the MIT License.
+
+## Description
+
+SpeedDial is a CLI bookmarking & shortcuts utility, allowing you to alias and index directory paths within 'entry groups', manage directory 'listings' *(SpeedDial will list out the children of a 'listing' and ask which you'd like to make your new current working directory)*, and swap your current working directory quickly by targeting entries or listings.
+
+## Installation & Usage
+
+### Dependencies
+
+[Node 0.6+](http://nodejs.org/) or greater is required to run SpeedDial. SpeedDial has so far only been tested on Mac OS.
+
+### Installation
+
+ 1. Install the node package by running `npm install speed-dial --global`
+ 2. Reload your terminal session to make the `speed-dial` binary available
+ 3. Run `speed-dial init`. Specify the path to a file of your choice that your terminal sources. `~/.bash_profile` or `~/.zsh_profile` are good choices for [bash](http://www.gnu.org/software/bash/) and [zsh](http://www.zsh.org/) users respectively
+ 4. Reload your terminal session once more so your terminal can source SpeedDial's `functions` file
+
+## Usage
+
+SpeedDial's `init` command sources a bash script from the package making a few commands to interact with SpeedDial available.
+
+ - `sd`: The main speed-dial interface
+ - `s`: Shortcut to `sd go [alias|id]`
+
+These `sd` and `s` commands should be your sole method for interacting with SpeedDial. Technically you can interact with SpeedDial without issue using the provided `speed-dial` binary directly, however when calling `speed-dial go [...]` no redirection will occur on exit of the script.
+
+### An Important Note
+
+**SpeedDial should not be run directly using the node package's `bin/speed-dial` binary.**
+
+There is an inherent issue trying to change the terminal's current working directory from within a child process. Changing the current working directory from within SpeedDial only changes the directory of the child process SpeedDial is running within and only for the duration of the script's execution. Once SpeedDial finishes execution, returning focus back to the main terminal's process, the current working directory will remain as it was prior to executing the SpeedDial command.
+
+SpeedDial works around this limitation by writing the target directory to a file in `/tmp` just before it's process exits. When calling SpeedDial through the available shell functions, the target directory is read from the `/tmp` file and the appropriate `cd [target directory]` command is executed directly within the terminal's process.
+
+**If anyone would like to suggest a better *(and multi-user-friendly)* alternative, please [create an issue](https://github.com/deefour/SpeedDial/issues/new) or send a pull request.**
+
+### Available Commands
+
+Like git, the SpeedDial command delegates to subcommands based on its first argument. The most common subcommands are:
+
+#### sd init
+
+`sd init`
+
+Should only be run once, immediately after installing the SpeedDial node package. A line like the following one is appended to the file you specify when prompted.
+
+```bash
+# Loads SpeedDial functions
+. /path/to/system/node_modules/speed-dial/assets/functions
+```
+
+#### sd version
+
+`sd version`
+
+Prints the currently installed version of SpeedDial.
+
+#### sd list
+
+`sd list [group] [options]`
+
+Lists the SpeeDial entries for all groups and listings if no `[group]` is specified. `--raw` can be passed to `[options]` to print a [prettyjson](https://github.com/rafeca/prettyjson) dump of the raw SpeedDial JSON storage in it's entirety.
+
+```bash
+sd list # lists all entries and listings by group
+sd list default # lists the entries for the default group
+sd list work # lists the entries for the 'work' group
+sd list listings # lists the 'listings' entries
+sd list work --raw # lists the raw SpeedDial JSON storage for the 'work' group
+```
+
+Whenever the `list` command is executed, directly by you or internally by SpeedDial, the entries are ordered by the following criteria
+
+ 1. Ascending by entry weight
+ 2. Without alias, then *with* alias
+ 3. Ascending alphabetically
+
+#### sd group
+
+`sd group [name]`
+
+Prints the name of the currently active group if `[name]` is not provided. If `[name]` *is* provided, SpeedDial's currently active group will be changed.
+
+```bash
+sd group # prints 'default'
+sd group work # changes currently active group to 'work'
+sd group # prints 'work'
+```
+
+When running a command like `sd go [alias|id]` *(or `s [alias|id] for short`)*, SpeedDial will restrict it's lookup to the currently active group. By switching the active group as you shift focus throughout the day, you can avoid the need to pass the group name to `s` when performing a lookup.
+
+#### sd add
+
+`sd add [path] [alias] [options]`
+
+```bash
+sd add ~/Sites/Deefour.me # Adds /Users/deefour/Sites/Deefour.me to the currently active group with no alias
+sd add ~/Documents docs # Adds /Users/deefour/Documents to the currently active group with alias 'docs'
+sd add ~/Work/Project1 --group work # Adds /Users/deefour/Work/Project1 to the 'work' group with no alias
+sd add ~/Work/Project2 p2 --group work # Adds /Users/deefour/Work/Project2 to the 'work' group with alias 'p2'
+sd add ~/Media/Audio/iTunes mp3s --weight 4 # Adds /Users/deefour/Media/Audio/iTunes to the currently active group with a weight of 4
+```
+
+Adds a new entry to SpeedDial. The `[alias]` is optional, as SpeedDial can lookup an entry based on it's ID within it's group by running `s [entry ID]` *(this is explained more in `sd go` below)*.
+
+#### sd addlisting
+
+`sd addlisting [path] [alias]`
+
+Adds a new listing to SpeedDial. Both `[path]` and `[alias]` are required. **Note:** Listing aliases must be unique to other listing aliases *and* from all group names.
+
+```bash
+sd addlisting ~/Sites sites # adds a new listing with alias 'sites' for path '/Users/deefour/Sites`
+```
+
+#### sd remove
+
+`sd remove`
+
+Lists all entries by group and all listings, with an incrementing ID value that is not reset for each group or the listings. Prompts for the ID value corresponding to the entry or listing to be removed. After confirmation, the entry or listing will be removed from the SpeedDial storage.
+
+*For a user-created entry group, if no entries remain in the group after the one specified was removed, the user-created entry group will be removed from the SpeedDial storage too.*
+
+#### sd go & s
+
+`sd go [group|alias|ID] [alias|ID]`
+
+```bash
+sd go # Lists all entries and listings, prompting the user to select one
+sd go work # Lists all entries for the 'work' entry group, prompting the user to select one
+sd go listings # Lists all listings, prompting the user to select one
+sd go listing sites # Lists the child directories of the path associated with the 'sites' alias listing, prompting the user to select one
+sd go me # (Assuming 'me' is an alias in the curently active group) Switches the current working directory to the path associated with the 'me' alias in the currently active group
+sd go work 1 # Switches the current working directory to the entry associated with ID '1' in the 'work' entry group
+```
+
+This command obeys the following logic
+
+ 1. For calls without an alias/ID specified and those for a specific listing, SpeedDial will list all entries/listings and prompt the user to select an ID for the entry/listing to switch to
+ 2. If a group is provided without an alias, SpeedDial will list all entries for the group and prompt the user to select an ID for the entry to switch to
+ 3. If a listing is specified, SpeedDial will list all child directories of the listing path and prompt the user to select an ID for the child directory to switch to
+ 4. If both a group/listing and alias/ID are provided, the user will not be prompted for anything; the current working directory will be changed immediately
+
+*The bash command function `s` is provided as a shortcut to `sd go`. Since SpeedDial is about minimizing keystrokes required to change a directory, it's recommended you always use `s` in favor of `sd go`.*
+
+## Notes
+
+- Group names and listing aliases must be globally unique
+- Group names, entry aliases, and listing aliases must all start with a letter and may only contain letters, numbers, underscores, and hyphens
+
+## Changelog
+
+### Version 0.1.0 - November 13 2012
+
+Initial project release
+
+- No tests available yet
+- A great deal of refactoring/cleaning to do
115 app.js
@@ -0,0 +1,115 @@
+var flatiron = require('flatiron'),
+ colors = require('colors')
+ path = require('path'),
+ util = require('utile'),
+ _ = require('lodash'),
+ appName = require('./package.json').name;
+
+
+
+var app = module.exports = flatiron.app;
+
+// Set $HOME properly for windows
+if (process.platform == "win32") {
+ process.env.HOME = process.env.USERPROFILE;
+}
+
+
+
+// Setup some basic options/usage instructions for flatiron
+// an the related cli plugin
+app.use(flatiron.plugins.cli, {
+ dir: path.join(__dirname, 'lib', 'commands'),
+ argv: {
+ usage: [
+ 'mm'
+ ],
+ colors: {
+ description: '--no-colors will disable output coloring',
+ default: true,
+ boolean: true
+ },
+ notFoundUsage: []
+ }
+});
+
+defaults = {
+ 'currentGroup': 'default',
+ 'storageFile': path.join(process.env.HOME, util.format('.%s.json', appName)),
+ 'tmpDirFile': '/tmp/speed-dial'
+};
+app.config.file({ file: path.join(__dirname, util.format('%s-config.json', appName)) });
+app.config.defaults(defaults);
+
+app.use(require('flatiron-cli-config'), {
+ store: 'file',
+ restricted: [
+ 'currentGroup',
+ 'storageFile'
+ ]
+});
+
+
+
+// Logging options
+app.options.log = {
+ console: {
+ raw: app.argv.raw
+ }
+};
+
+
+
+// Commonly used prompts (ie. confirmation prompt)
+app.prompt.properties = flatiron.common.mixin(
+ app.prompt.properties,
+ {
+ yesno: {
+ name: 'yesno',
+ message: 'Are you sure?',
+ validator: /y[es]*|n[o]?/,
+ warning: 'Must respond yes or no',
+ default: 'no'
+ }
+ }
+);
+
+app.prompt.override = app.argv;
+
+
+
+// Startup the flatiron app
+app.start = function(callback) {
+ // Allow coloring in the console output to be disabled
+ var useColors = (typeof app.argv.colors == 'undefined' || app.argv.colors);
+
+ useColors || (colors.mode = "none");
+
+ app.init(function(err) {
+ if (!useColors) {
+ app.log.get('default').stripColors = true;
+ app.log.get('default').transports.console.colorize = false;
+ }
+ });
+
+ // Set a default command if speed-dial is run without any command
+ if (_.isEmpty(app.argv._)) {
+ app.argv._ = ['list'];
+ }
+
+ return app.exec(app.argv._, callback);
+};
+
+
+// Overload implementation of flatiron's exec; attempts to handle errors within the
+// application's commands gracefully and help with routing
+app.exec = function (command, callback) {
+ app.router.dispatch('on', command.join(' '), app.log, function (err, shallow) {
+ if (err) {
+ app.log.error(err.message);
+ if (!_.isUndefined(callback)) callback(err);
+ }
+
+ if (!_.isUndefined(callback)) callback(err);
+ });
+}
@@ -0,0 +1,16 @@
+function s() {
+ sd go $*
+}
+
+function sd() {
+ node ~/Repos/Deefour/speed-dial/bin/speed-dial $*
+
+ if [ "$1" = "go" ]; then
+ file="/tmp/speed-dial"
+
+ dir=`tail -1 $file`
+ dir=`expr "$dir" : '[[:space:]]*\(.*\)[[:space:]]*$'`
+
+ cd "$dir"
+ fi
+}
@@ -0,0 +1,4 @@
+#!/usr/bin/env node
+
+// Get things started
+require('../lib/cli').start();
@@ -0,0 +1,12 @@
+var app = module.exports = require('../app'),
+ storage = require('./storage');
+
+
+
+// Initial load, brings JSON data from the storage into memory
+storage.load(
+ app.config.get('storageFile'),
+ function(err) {
+ if (err) throw err;
+ }
+);
Oops, something went wrong.

0 comments on commit d635755

Please sign in to comment.