Skip to content

Instantly share code, notes, and snippets.

@guiprav
Last active August 29, 2015 14:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guiprav/00f9acbaccce79fc44d2 to your computer and use it in GitHub Desktop.
Save guiprav/00f9acbaccce79fc44d2 to your computer and use it in GitHub Desktop.
grab / recycle shell scripts.

Installation

$HOME/.grabbed_outputs/ must exist before invoking the commands. It should configured 0700 for security.

Example usage

$ echo Foo. | grab
Foo.
$ recycle
Foo.
$ echo Bar. | grab bar
Bar.
$ recycle
Foo.
$ recycle bar
Bar.
$ echo Baz. | grab baz
Baz.
$ recycle baz
Baz.
$ recycle; recycle bar; recycle baz
Foo.
Bar.
Baz.

File-specific examples (With personal aliases)

$ # Find occurrences of 'comments_number' and grab output:

$ ack-grep comments_number --php -il |gg
wp-admin/includes/class-wp-list-table.php
wp-includes/theme-compat/comments.php
wp-includes/feed-atom.php
wp-includes/feed-rss2.php
wp-includes/comment-template.php
wp-content/plugins/comment-popularity/inc/templates/comments.php
wp-content/plugins/automatic-youtube-video-posts/core/video.php
wp-content/plugins/jetpack/modules/related-posts/jetpack-related-posts.php
wp-content/themes/positivo/archive-canal-do-diretor.php
wp-content/themes/positivo/single-canal-do-diretor.php
wp-content/themes/positivo/templates/single/single-video.php
wp-content/themes/positivo/templates/single/single-post.php
wp-content/themes/omega/partials/comments-loop.php
wp-content/themes/omega/lib/functions/shortcodes-post.php
wp-content/themes/twentyfourteen/content-aside.php
wp-content/themes/twentyfourteen/content-quote.php
wp-content/themes/twentyfourteen/content-link.php
wp-content/themes/twentyfourteen/inc/widgets.php
wp-content/themes/twentyfourteen/content-video.php
wp-content/themes/twentyfourteen/single.php
wp-content/themes/twentyfourteen/content.php
wp-content/themes/twentyfourteen/content-audio.php
wp-content/themes/twentyfourteen/content-image.php
wp-content/themes/twentyfourteen/page-templates/contributors.php
wp-content/themes/twentyfourteen/page-templates/full-width.php
wp-content/themes/twentyfourteen/content-gallery.php
wp-content/themes/twentyfourteen/comments.php
wp-content/themes/twentyfourteen/page.php
wp-content/themes/focusmagazine/framework/widgets/category_posts/tpl/list.php
wp-content/themes/focusmagazine/framework/widgets/category_posts/tpl/stack.php
wp-content/themes/focusmagazine/comments.php

$ # Filter some results and grab them again:

$ rr |grep -e positivo -e focus |gg
wp-content/themes/positivo/archive-canal-do-diretor.php
wp-content/themes/positivo/single-canal-do-diretor.php
wp-content/themes/positivo/templates/single/single-video.php
wp-content/themes/positivo/templates/single/single-post.php
wp-content/themes/focusmagazine/framework/widgets/category_posts/tpl/list.php
wp-content/themes/focusmagazine/framework/widgets/category_posts/tpl/stack.php
wp-content/themes/focusmagazine/comments.php

$ # Open them all using $EDITOR:

$ rre
... vim session with all above files open ...
#!/bin/sh
ID=$1
if [ -z "$ID" ];
then
ID="_"
fi
FILE="$HOME/.grabbed_outputs/$ID"
TMP="$HOME/.grabbed_outputs/.$$"
tee "$TMP" </dev/stdin
mv "$TMP" "$FILE"
#!/bin/sh
ID=$1
if [ -z "$ID" ];
then
ID="_"
fi
FILE="$HOME/.grabbed_outputs/$ID"
if [ ! -f "$FILE" ];
then
echo "$FILE does not exist." >/dev/stderr
exit 1
fi
cat "$FILE"
#!/bin/sh
cat $(recycle $1)
#!/bin/sh
$EDITOR $(recycle $1)
alias gg=grab
alias rr=recycle
alias rrc=recycle-cat-files
alias rre=recycle-edit-files
function rrcd() {
cd $(recycle $1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment