Skip to content

Instantly share code, notes, and snippets.

Brett Terpstra ttscoff

Block or report user

Report or block ttscoff

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ttscoff
ttscoff / convert_to_quiver.rb
Created Apr 30, 2020
Markdown files to Quiver JSON
View convert_to_quiver.rb
#!/usr/bin/env ruby
require 'json'
require 'fileutils'
notebook = File.expand_path('~/Desktop/NewSnippets.qvnotebook')
FileUtils.mkdir_p(notebook)
nbmeta = {
"name" => "NewSnippets",
"uuid" => %x{uuidgen}.strip
@ttscoff
ttscoff / mmdtagstomacos.rb
Last active Apr 18, 2020
Read MultiMarkdown metadata tags from files and apply them as macOS tags
View mmdtagstomacos.rb
#!/usr/bin/env ruby
# encoding: utf-8
#
# Read MultiMarkdown metadata tags from files and apply them as macOS tags
#
# Usage:
# mmdtagstomacos.rb *.md
require 'shellwords'
mmd = '/usr/local/bin/multimarkdown'
@ttscoff
ttscoff / dadjoke.fish
Created Feb 18, 2020
Dad jokes for Fish shell
View dadjoke.fish
# You're welcome
function dadjoke -d 'Get a dad joke from icanhazdadjoke.com'
curl -H "Accept: text/plain" https://icanhazdadjoke.com/
end
@ttscoff
ttscoff / tunes.rb
Created Feb 15, 2020
CLI controls for Spotify and (Apple) Music
View tunes.rb
#!/usr/bin/env ruby
# encoding: utf-8
#
# CLI music controller for Spotify and Apple Music
# By default affects whichever one is running, preferring Spotify
# if both are. Change the order of KNOWN_PLAYERS to reverse that.
#
# If the first argument is either "music" or "spotify," it will
# target that app. If the app is not running, it will be launched.
# When no app is specified and neither are running, it returns nothing
@ttscoff
ttscoff / tm.fish
Created Dec 17, 2019
Fish completion for tm.bash
View tm.fish
# ~/.config/fish/completions/tm.fish
function __tm_has_no_args
set -l cmd (commandline -opc)
echo $cmd
return (test (count $cmd) -eq 1)
end
function __tm_has_windows
set -l cmd (commandline -opc)
set -l res (tmux list-windows -t $cmd[-1] 2>/dev/null >/dev/null)
@ttscoff
ttscoff / commandline.fish
Last active Nov 11, 2019
Fish functions with commandline tricks
View commandline.fish
# Defined in /Users/ttscoff/.config/fish/functions/__prev_token.fish @ line 1
function __prev_token -d "repeats last token on the command line"
set -l buffer (commandline -bo)
commandline -a " "$buffer[-1]
commandline -f end-of-line
end
# Defined in /Users/ttscoff/.config/fish/functions/__re_extension.fish @ line 1
function __re_extension --description 'remove extension from word under/before cursor'
commandline -f forward-word
@ttscoff
ttscoff / bid.fish
Created Nov 9, 2019
bid command for Fish
View bid.fish
# Defined in /Users/ttscoff/.config/fish/brett.fish @ line 240
function bid --description 'Get bundle id for app name'
set -l shortname (echo "$argv"| sed -E 's/\.app$//'|sed 's/\\\//g')
set -l location
# if the file is a match in apps folder, don't spotlight
if test -d "/Applications/$shortname.localized/$shortname.app"
set location "/Applications/$shortname.localized/$shortname.app"
else if test -d "/Applications/$shortname.app"
set location "/Applications/$shortname.app"
@ttscoff
ttscoff / fish_prompt.fish
Last active Nov 27, 2019
Brett's fish prompt, based on Bira
View fish_prompt.fish
# biras_weird_cousin
# Theme based on Bira theme from oh-my-zsh: https://github.com/robbyrussell/oh-my-zsh/blob/master/themes/bira.zsh-theme
# Some code stolen from oh-my-fish clearance theme: https://github.com/bpinto/oh-my-fish/blob/master/themes/clearance/
# Adds a badge if we're in an SSH session (first letter of hostname, uppercased)
function __ssh_badge
if test -n "$SSH_CLIENT$SSH2_CLIENT$SSH_TTY"
set_color -b d6aeec -o 2a0a8b
echo -n " "(string upper (string sub -s 1 -l 1 (hostname -s)))" "
set_color normal
@ttscoff
ttscoff / brett.fish
Last active Feb 8, 2020
Brett's Fish Shell custom init file
View brett.fish
function __should_na
set -l cmd (history --max=1|awk '{print $1;}')
set -l cds cd z j popd g
if contains $cmd $cds
~/scripts/fish/na
end
end
function fallback --description 'allow a fallback value for variable'
if test (count $argv) = 1
@ttscoff
ttscoff / linkmarks.rb
Last active Oct 11, 2019
A script to convert Bashmarks .sdirs file to Fish's Jump plugin symlinks
View linkmarks.rb
#!/usr/bin/env ruby
# A script to convert Bashmarks .sdirs file to Fish's Jump plugin symlinks
sdirs_file = File.expand_path('~/.sdirs')
unless File.exists?(sdirs_file)
$stderr.puts 'Bookmarks file not found (~/.sdirs). Is Bashmarks initialized?'
Process.exit 1
end
marks = File.expand_path('~/.marks')
You can’t perform that action at this time.