Git Product home page Git Product logo

pluc's Introduction

logo

๐Ÿ‘Œ Create permanent terminal aliases instantly

โš ๏ธUnder construction, beware of breaking changes โš ๏ธ


NPM version Build Status

Usage

Save a new alias forever

$ pluc <alias> <command>

Leave out "command" and pluc will use your last command from shell history.

$ pluc <alias>

Here's what this could look like:

$ pluc serve "python -m SimpleHTTPServer"

๐Ÿ‘Œ Aliased "serve" to "python -m SimpleHTTPServer" ๐Ÿ‘Œ

or

$ pluc ya "yarn add"

๐Ÿ‘Œ Aliased "ya" to "yarn add" ๐Ÿ‘Œ

$ ya react #Your new alias is instantly usable

Install

  1. npm install
$ npm install --global pluc
  1. Source pluc in your shell

Now source the pluc output file in your shell. Paste this in your bash profile (~/.bashrc, ~/.zshrc, ~/.bash_profile, , or ~/.profile).

source "$(pluc-cli --destinationPath)" #source pluc aliases on shell startup
function pluc() { #call pluc-cli and source new alias immediatly
  pluc-cli "$@"
  source "$(pluc-cli --destinationPath)"
}

Should you ignore the above bash code, you'd need to manually resource the pluc shell file per session and after adding a new alias.


Verify Installation

$ pluc --sourcePath
# Should output a json filepath, not an error.

Your bash aliases are generated from that JSON object. You don't need to pay attention to that in most cases. That's covered in depth in the "About" section below.


More Examples

Imagine you ssh to this machine often:

$ ssh [email protected]
# ssh: Successfully ssh'd to example.org!

But truly, you do that most days. Why should you type it out?

$ pluc sshme
# ๐Ÿ‘Œ Aliased "sshme" to "ssh [email protected]" ๐Ÿ‘Œ

$ sshme
# ssh: Successfully ssh'd to example.org!

Not only is the alias sshme instantly available, it's forever available in any new sessions. The alternative is to save an alias in your bash profile. It's not only time consuming to open and edit, but you won't be able to use that alias until you source it.


Or let's say you do web development and need a web server often:

$ pluc serve "python -m SimpleHTTPServer"
# ๐Ÿ‘Œ Aliased "serve" to "python -m SimpleHTTPServer" ๐Ÿ‘Œ

$ serve
# Serving HTTP on 0.0.0.0 port 8000 ...

Although it's always recommended that you quote the command for safety with bash argument splitting, your second argument can contain spaces! Parsing of this is done on your behalf by pluc. If your command contains flags though, you must quote it, which is why it's not a good habit.


If you want to see the full list of commands:

$ pluc --help

About

pluc uses a single JSON object to store aliases. Since JSON is already key-value based, it's a perfect data format. To manually edit the JSON source file (you absolutely will eventually) enter

$ $EDITOR $(pluc --sourcePath)

After any new alias is added to pluc, the render function is called which builds a shell file. The shell output is what you source'd at the very beginning. To see it right now, enter

$ $EDITOR $(pluc --destinationPath)

โš ๏ธ Do not edit the output shell file, it gets deleted on re-render (often) โš ๏ธ


Backup important aliases

Are you saving important aliases or a large amount of them? If so, back these up.

Backup to Dropbox

First find the path your config file is saved in:

$ pluc --sourcePath
# /Users/dawsonbotsford/Library/Preferences/pluc-nodejs/config.json

This file needs to be moved into Dropbox and symlinked back to the original location

mv /Users/dawsonbotsford/Library/Preferences/pluc-nodejs/config.json ~/Dropbox/
ln -s ~/Dropbox/config.json /Users/dawsonbotsford/Library/Preferences/pluc-nodejs/config.json

Backup to git

Alternatively, use git to manually version control.

$ pluc --sourcePath
# /Users/dawsonbotsford/Library/Preferences/pluc-nodejs/config.json
$ cd /Users/dawsonbotsford/Library/Preferences/pluc-nodejs
$ git init
# add remote, and push!

FAQ

  • Why not use the source command in my terminal?

    • source is only available within your current shell. As soon as you start a new session, your alias is gone.
  • How can I edit my aliases?

    • $ $EDITOR $(pluc --sourcePath)
  • Why store the data as a JSON object?

    • If JSON objects are used as the source of truth, a variety of render methods can be used. This means that any output format (vimrc, sublime snippets, etc.) which is key-value based can be generated using pluc.
  • What's one of these "pluc JSON objects" actually look like?

{
  "gi": "git init",
  "ga": "git add"
}
  • The history inferred by pluc <alias> alone is not accurate.

Compatibility Issues

  • pluc will not create valid aliases on Windows. Windows does not save terminal history.

  • pluc will not work with fish shell. It likely will not work for shells beyond bash or zsh. This is because of the parse function in @dawsbot/shell-history package. PR's welcome.

License

MIT ยฉ Dawson Botsford

pluc's People

Contributors

dawsbot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

tech-cow

pluc's Issues

Triage infinite loop

screen shot 2017-02-02 at 3 19 03 pm

Occurs when you are plucing things which contain pluc. That's a hanging infinite loop in the picture ^:

sist output:

node

npm -v: 4.0.5
node --version: v6.9.4

shell

uname: Darwin
echo $SHELL: /bin/zsh
echo $TERM: xterm-256color
echo $TERM_PROGRAM: iTerm.app

Time created: Thu Feb 02 2017 15:20:41 GMT-0800 (PST)

๐Ÿ› Deletion of entire alias file

I think this is why: Under situations where config.json is invalid json,

The entire file is deleted upon transpilation of aliases. This is an issue because it means if you do not backup your aliases, all are gone when executing pluc --transpile.

A proposed fix would be to avoid writing to config.json if the object is empty or smaller than the previous object.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.