Skip to content

Instantly share code, notes, and snippets.

@shaundon
Created May 25, 2017 14:03
Show Gist options
  • Save shaundon/af23d393ec63c6485990292a5fa2acbe to your computer and use it in GitHub Desktop.
Save shaundon/af23d393ec63c6485990292a5fa2acbe to your computer and use it in GitHub Desktop.

Bash functions

Some functions I have installed in my ~/.bash_profile to make life easier. Source code

clone

Description

Clone a repo into your projects folder and cd into it.

Code

function clone {
    cd ~/projects;
    git clone $1;
    reponame=$(basename $1);
    cd ${reponame/.git/};
}

Example usage

$ clone git@github.com:jezen/is-thirteen.git
Cloning into 'is-thirteen'...
remote: Counting objects: 934, done.
remote: Total 934 (delta 0), reused 0 (delta 0), pack-reused 934
Receiving objects: 100% (934/934), 151.95 KiB | 0 bytes/s, done.
Resolving deltas: 100% (570/570), done.

shaundonnelly at shaudonn01m in ~/projects/is-thirteen on master
# We've cloned the repo and we're now inside it.

repo

Description

Open the current repository in your default browser.

Code

function show-repo {
    git remote -v | grep origin | awk ' { print $2 }' | uniq | tr ':' '/' | sed "s|git\@|http://|"
}.
function repo {
    show-repo | xargs open
}

Example usage

shaundonnelly at shaudonn01m in ~/projects/is-thirteen on master
$ repo
# (https://github.com/jezen/is-thirteen opens in my browser)

npm-do

Description

Allows you to run locally installed npm packages without needing them to be installed globally.

Code

function npm-do {
  (PATH=$(npm bin):$PATH; eval $@;)
}

Example usage

# Show that webpack is installed as a dependency.
$ npm ls --depth=0
test@1.0.0 /Users/shaundonnelly/Desktop/test
└── webpack@2.6.1

# Try to run webpack without installing it globally first, doesn't work.
$ webpack
-bash: webpack: command not found

# Run webpack via `npm-do`, it now works as it's installed locally in the current project.
$ npm-do webpack
No configuration file found and no output filename configured via CLI option.
A configuration file could be named 'webpack.config.js' in the current directory.
Use --help to display the CLI options.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment