-
-
Save g2g/ffe1bf0ac960251516030cd3f4fbb5ba to your computer and use it in GitHub Desktop.
Simple shell script using commandlinefu.com API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# commandlinefu - Simple shell script using commandlinefu.com API | |
# | |
# All commands sorted by date: | |
# % commandlinefu | |
# | |
# All commands sorted by votes: | |
# % commandlinefu -v | |
# | |
# Search results for the query 'ssh' sorted by date: | |
# % commandlinefu ssh | |
# | |
# Search results for the query 'ssh' sorted by votes: | |
# % commandlinefu -v ssh | |
# | |
# You can learn more about commandlinefu.com API at the following link: | |
# https://www.commandlinefu.com/site/api | |
# | |
# Original script: | |
# http://commandlinefu.uservoice.com/forums/11102-general/suggestions/116596-provide-bash-client-to-integrate-site-into-cli | |
# | |
# Seungwon Jeong <seungwon0@gmail.com> | |
# | |
# Copyright (C) 2011 by Seungwon Jeong | |
set -e | |
if test "$1" = -v; then | |
sort=sort-by-votes | |
shift | |
fi | |
base_url=https://www.commandlinefu.com/commands | |
if test "$1"; then | |
query=$1 | |
base64=`echo -n $query | base64` | |
command_set=matching/$query/$base64 | |
else | |
command_set=browse | |
fi | |
if test "$sort"; then | |
command_set=$command_set/$sort | |
fi | |
format=plaintext | |
url=$base_url/$command_set/$format | |
if test -t 1; then | |
curl -s $url | source-highlight -s sh -f esc | less -R | |
else | |
curl -s $url | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment