Skip to content

Instantly share code, notes, and snippets.

View ttscoff's full-sized avatar
💭
Breathing

Brett Terpstra ttscoff

💭
Breathing
View GitHub Profile
#!/bin/bash
# Bash completion for `up` <http://brettterpstra.com/2014/05/14/up-fuzzy-navigation-up-a-directory-tree/>
_up_complete()
{
local rx
local token=${COMP_WORDS[$COMP_CWORD]}
local IFS=$'\t'
local words=$(dirname `pwd` | tr / " ")
local nocasematchWasOff=0
@ttscoff
ttscoff / up.sh
Last active February 20, 2025 09:42
up: Quickly cd up a directory tree
# inspired by `bd`: https://github.com/vigneshwaranr/bd
function _up() {
local rx updir
rx=$(ruby -e "print '$1'.gsub(/\s+/,'').split('').join('.*?')")
updir=`echo $PWD | ruby -e "print STDIN.read.sub(/(.*\/${rx}[^\/]*\/).*/i,'\1')"`
echo -n "$updir"
}
function up() {
if [ $# -eq 0 ]; then
@ttscoff
ttscoff / tm.bash
Last active September 10, 2024 19:55
A shell function to wrap tmux and make the basic commands a bit easier
#!/bin/bash
__lower() {
echo "$@"|tr "[:upper:]" "[:lower:]"
}
__menu() {
local result=""
PS3=$1
shift
@ttscoff
ttscoff / folderize.rb
Created May 4, 2014 13:37
A script to create nested folders from a flat folder containing files with configured prefixes
#!/usr/bin/env ruby
require 'yaml'
require 'fileutils'
class Folderize
def initialize(config_file=false)
config_file = File.expand_path("~/.folderize") unless config_file
# Set up config
unless File.exists?(config_file)
@ttscoff
ttscoff / spl.rb
Created May 2, 2014 14:46
A Sentaku-based wrapper for mdfind
#!/usr/bin/ruby
require 'shellwords'
query = ARGV.length > 0 ? ARGV.join(" ") : "date:today"
files = %x{mdfind '#{ARGV.join(" ")}'}.split("\n")[0..100]
filehash = {}
files.each {|file|
base = File.basename(file)
@ttscoff
ttscoff / total_numbers.rb
Created April 7, 2014 19:42
Sum all numbers found in the input
#!/usr/bin/ruby
decimal = "."
separator = ","
if RUBY_VERSION.to_f > 1.9
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
input = STDIN.read.force_encoding('utf-8')
else
@fcrespo82
fcrespo82 / .bash_completion
Last active August 29, 2015 13:57
A shell completion for Brett Terpstra's doing command line utility http://brettterpstra.com/projects/doing/
_doing()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$(doing help -c)" -- $cur) )
}
complete -F _doing doing
@ttscoff
ttscoff / Instant Search.applescript
Last active February 20, 2025 09:46
A LaunchBar action to use SearchLink as a quick access tool for the web.
(* Instant Search for LaunchBar by Brett Terpstra
Requires SearchLink installed in ~/Library/Services (http://brettterpstra.com/projects/searchlink/)
Load the service in LaunchBar and type Space. Enter text, optionally starting with a SearchLink !arg
to define the desired search engine. (You do not need the "!!" at the end to specify only url).
The link will be returned, pressing Enter will open it. ⌘C will copy.
*)
on handle_string(message)
set _chars to reverse of characters of message
@ttscoff
ttscoff / image_tag.rb
Created February 16, 2014 15:02
Custom Jekyll image tag with lazy loading and CDN changes
# Title: Simple Image tag for Jekyll
# Authors: Brandon Mathis http://brandonmathis.com
# Felix Schäfer, Frederic Hemberger
# Description: Easily output images with optional class names, width, height, title and alt attributes
#
# Syntax {% img [class name(s)] [http[s]:/]/path/to/image [width [height]] [title text | "title text" ["alt text"]] %}
#
# Examples:
# {% img /images/ninja.png Ninja Attack! %}
# {% img left half http://site.com/images/ninja.png Ninja Attack! %}
@ttscoff
ttscoff / Open Together Note in Marked.applescript
Created January 20, 2014 02:38
Quick AppleScript for opening the selected [Together 3](http://reinventedsoftware.com/together/) note(s) in [Marked.app](http://marked2app.com)
tell application "Together 3"
set _sel to selected items
repeat with _note in _sel
set _file to original filename of _note
tell application "Marked" to open POSIX path of _file
end repeat
end tell