Skip to content

Instantly share code, notes, and snippets.

@colstrom
Last active December 9, 2016 06:52
Show Gist options
  • Select an option

  • Save colstrom/80b844c38babdd03f32fae27bff41ce5 to your computer and use it in GitHub Desktop.

Select an option

Save colstrom/80b844c38babdd03f32fae27bff41ce5 to your computer and use it in GitHub Desktop.
lines-before.fish: prints lines that occur before a given pattern
name = lines-before
author = Chris Olstrom
license = MIT
provides = fish/functions/lines-before
requires
command/awk
fish/builtin/case
fish/builtin/count
fish/builtin/echo
fish/builtin/end
fish/builtin/function
fish/builtin/return
fish/builtin/switch
function lines-before --argument pattern
switch (count $argv)
case 0
echo 'usage: lines-before <pattern>'
return 100
case '*'
awk "/$pattern/ { exit }; 1"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment