Skip to content

Instantly share code, notes, and snippets.

View colstrom's full-sized avatar

Chris Olstrom colstrom

View GitHub Profile
#! /bin/sh
# -*- shell-script -*-
# The MIT License (MIT)
# Copyright (c) 2017 Chris Olstrom <[email protected]>
# Copyright (c) 2017 SUSE LLC
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
#!/usr/bin/env ruby
require 'set'
data = Dir
.glob('*')
.reject { |file| file.end_with? '.rb' }
.map { |os| [os, File.read(os)] }
.map do |os, info|
[
@colstrom
colstrom / directory-in-git.fish
Created December 9, 2016 20:36
directory-in-git.fish: check if a directory is or is in a git repository
function directory-in-git --argument dir
git -C "$dir" rev-parse --is-inside-working-tree >/dev/null ^/dev/null
status-to-bool $status
end
@colstrom
colstrom / gistpkg.zpl
Created December 9, 2016 20:22
tab.fish: sugar for printing literal tabs
name = tab
author = Chris Olstrom
license = MIT
provides = fish/functions/tab
requires
fish/builtin/end
@colstrom
colstrom / gistpkg-manifest.fish
Created December 9, 2016 20:19
gistpkg-manifest.fish: generate gistpkg.zpl from a .fish function
function gistpkg-manifest --argument file
switch (count $argv)
case 0
echo 'usage: gistpkg-manifest <file>'
return 100
case '*'
set name (basename -s .fish $file)
printf "name = %s\n\n" $name
@colstrom
colstrom / gistpkg.zpl
Created December 9, 2016 20:14
with-cwd-as.fish: executes commands in another directory
name = with-cwd-as
author = Chris Olstrom
license = MIT
provides = fish/functions/with-cwd-as
requires
fish/builtin/and
@colstrom
colstrom / gistpkg.zpl
Created December 9, 2016 20:11
user-is-root.fish: checks if the current user is root
name = user-is-root
author = Chris Olstrom
license = MIT
provides = fish/functions/user-is-root
requires
command/id
@colstrom
colstrom / gistpkg.zpl
Last active December 9, 2016 06:45
sonar-lexer.fish: a lexer for fish, written in fish
name = sonar-lexer
author = Chris Olstrom
license = MIT
provides = fish/functions/sonar-lexer
requires
fish/builtin/and
@colstrom
colstrom / gistpkg-list.fish
Last active December 9, 2016 19:20
gistpkg-list.fish: list installed gistpkgs
function gistpkg-list
set local (gistpkg-config root)/(gistpkg-config origin)
if test (is-a-directory $local) = true
find $local -type d -mindepth 1 -name .git -exec dirname '{}' \; | string replace --all --regex "^$local/" ''
end
end
@colstrom
colstrom / gistpkg-avail.fish
Last active December 9, 2016 18:45
gistpkg-avail.fish: list available gistpkgs from user
function gistpkg-avail --argument username
switch (count $argv)
case 0
echo 'usage: gistpkg-avail <username>'
return 100
case '*'
github-api /users/$username/gists | jq -r '.[] | select(.files | keys[] | test("^gistpkg.zpl$")) | [([.owner.login, .id] | join("/")), .description] | @tsv'
end
end