Skip to content

Instantly share code, notes, and snippets.

View adamheins's full-sized avatar

Adam Heins adamheins

View GitHub Profile
@adamheins
adamheins / dir_aliases.sh
Created September 21, 2015 06:02
Bash aliases for directory navigation.
#!/bin/bash
# Aliases for changing directories.
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias -- -="cd - >/dev/null 2>&1"
@adamheins
adamheins / colors.sh
Created September 21, 2015 06:05
Bash function for displaying all 256 colors with codes in the terminal.
#!/bin/bash
# Print all of the terminal colors.
colors() {
local count=0
local cols=$(tput cols)
for i in {0..255}; do
((count+=4))
if [ $count -gt $cols ]; then
printf "\n"
@adamheins
adamheins / jira.sh
Last active November 23, 2015 05:05
Simple tool for opening issues and starting a JIRA search from the command line (OSX).
#!/bin/bash
# Simple JIRA CLI utility.
# Currently only works on OSX (since it makes use of OSX's built-in
# open command).
jira() {
if [ -z "$1" ]; then
open "$JIRA_URL""/secure/Dashboard.jspa"
return 0
@adamheins
adamheins / git-branch.sh
Created September 21, 2015 06:16
Get the current branch for your git repo in bash.
#/bin/bash
# If the cwd is a git repo, display the branch name in the tmux status bar.
get_git_branch() {
if [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
local branch short_branch
branch=$(git symbolic-ref -q HEAD)
branch=${branch##refs/heads/}
branch=${branch:-HEAD}
short_branch=$(echo "$branch" | cut -c1-20)
@adamheins
adamheins / secrets.py
Created October 8, 2015 23:10
Python function for importing modules from hidden directories and files.
import imp
import os
def secret_import(path):
""" Alternative way to import a module that allows importing of hidden
directories and files. """
if os.path.isdir(path):
name = path.split(os.path.sep)[-1]
if name[0] == '.':
name = name[1:]
@adamheins
adamheins / git.sh
Last active October 31, 2015 02:24
Script to remove a submodule from a git repository.
# Sourced here:
# https://gist.github.com/2491147
#
# Modified by Adam Heins
#
# Usage: git submodule rm [-c] <path/to/submodule>
# You must be in the root of the git repository to use this command. The -c
# (or --clean) option indicates that the submodule files should also be removed
# from the working tree.
@adamheins
adamheins / fzf-key-bindings-extension.zsh
Created November 23, 2015 05:13
A modification to the fzf key-bindings file that makes ALT-C both cd to directories and open files.
# ALT-C - cd into the selected directory or open file
fzf-cd-widget() {
local p="${$(command \find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
-o -print 2> /dev/null | sed 1d | cut -b3- | $(__fzfcmd) +m):-.}"
if [ -d "$p" ]; then
cd "$p"
elif [ -f "$p" ]; then
"$EDITOR" < /dev/tty "$p"
else
echo "$p"
@adamheins
adamheins / t.zsh
Created December 13, 2015 23:55
Simple command line note taking script.
#!/bin/zsh
# Author: Adam Heins
# Date: 2015-10-22
t() {
# Make the ~/.t directory if it does not exist.
[ ! -d ~/.t ] && mkdir ~/.t
if [ -z "$1" ]; then
@adamheins
adamheins / keybase.md
Created October 7, 2016 20:35
Keybase identity proof.

Keybase proof

I hereby claim:

  • I am adamheins on github.
  • I am adamheins (https://keybase.io/adamheins) on keybase.
  • I have a public key whose fingerprint is BE6E 8AB0 440B 2DA4 9880 A284 8393 976B CE8F 5796

To claim this, I am signing this object:

@adamheins
adamheins / catkin_toplevel.py
Created February 24, 2017 02:44
Prints the root of the current catkin workspace, or prints nothing and exits with non-zero exit code if not in a catkin workspace.
#!/usr/bin/env python
from __future__ import print_function
import os
CMAKELISTS_FILE_NAME = 'CMakeLists.txt'