Skip to content

Instantly share code, notes, and snippets.

@ZacharyRSmith
Last active November 24, 2015 15:01
Show Gist options
  • Save ZacharyRSmith/3119d7a69236e1b2a1cc to your computer and use it in GitHub Desktop.
Save ZacharyRSmith/3119d7a69236e1b2a1cc to your computer and use it in GitHub Desktop.

This post is for people using a bash shell. I'm assuming you know about bash aliases and Sublime Text snippets. They make your life a lot easier. I'm also assuming you're like me: you're too lazy to set them up--at least the old-fashioned way. Let me show you how to make setting these up easier.

You can set up a bash alias with a command as easy as:

als gitpfom git\ push\ -f\ origin\ master

Bam. Your alias is made and ready to go:

gitpfom => git push -f origin master

This is possible with a bash function in your .bash_profile:

# Add alias and refresh source
# Ex. usage:
# $: als gpom git\ push\ origin\ master
# $: gpm
# => git push origin master 
als () {
  echo "alias" $1'="'$2'"' >> ~/.bash_profile
  source ~/.bash_profile
}

And to make a Sublime snippet, all I have to do is type this into my terminal:

mksnip

...which: 1st) asks me how to name my new .sublime-snippet file, then 2nd) opens up that new .sublime-snippet file with example code:

<snippet>
  <content><![CDATA[reduce(function (${2:acc}, ${1:prop}) {
  ${2:acc}[${1:prop}] = ${3:fn(prop)};
  return ${2:acc};
}, {})]]></content>
  <tabTrigger>red</tabTrigger>
  <scope>source.js</scope>
  <description>array.reduce(function (…) {…})</description>
</snippet>

I edit this, and bam. New Sublime snippet.

How?

I have this alias in my .bash_profile:

alias mksnip="sh /Users/zacharyryansmith/bin/make_sublime_snippet.sh"

which is this bash script:

#!/bin/bash
echo "ENTER FILENAME OF NEW SNIPPET..."
read INPUT

cp /Users/zacharyryansmith/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/array-reduce.sublime-snippet /Users/zacharyryansmith/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/$INPUT.sublime-snippet

subl /Users/zacharyryansmith/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/$INPUT.sublime-snippet

If I want to change a snippet, I use this alias:

alias chsnip="subl /Users/zacharyryansmith/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/"

which opens up my snippets folder in Sublime.

I hope that you can use some of these tricks in your own workflow. Happy coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment