Hacker News new | past | comments | ask | show | jobs | submit login

list:

    #!/usr/bin/env sh
    
    find | grep -- "$1"
If you are searching for a Python or a Java package / class, it will work because the dots in it will mean "any char" for grep and will match the slashes in its path.

oneline:

    #!/usr/bin/env sh
    tr '\n' ' '; echo
Puts anything you give in its standard input in one line.

L, my journaling tool (whenever I need to get something out of my head or be sure to find it later); I can edit and fix stuff by editing the file it generates after the fact:

    #!/bin/sh
    set -e

    CONFIG_FILE="${HOME}/.config/Ljournalrc";

    if [ ! -f "${CONFIG_FILE}" ]; then
        mkdir -p "$(dirname "$CONFIG_FILE")"
        printf 'JOURNAL_FILE="${HOME}/Documents/journal.txt"\n' >> "${CONFIG_FILE}"
        printf 'VIEWER=less\n'                                  >> "${CONFIG_FILE}"
        printf 'LESS='"'"'-~ -e +G'"'"'\n'                      >> "${CONFIG_FILE}"
    fi

    L=$(basename $0)

    usage() {
        cat <<HERE
    Usage:
        $L           - show the content of the journal
        $L message   - add message to the journal, with a date
        $L + message - add message to the previous entry in the journal
        $L -         - add stdin to the journal
        $L + -       - add stdin to the journal, without a date
        $L e         - edit the journal manually
        $L h, $L -h  - show this help

    Config file is in ${CONFIG_FILE}
    HERE
    }

    if [ "$1" = "h" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; then
        usage
        exit
    fi

    . "${CONFIG_FILE}"


    if [ "$1" = "e" ]; then
        if [ -z "$EDITOR" ]; then
            if   [ -f "$(which nano)" ];  then
                EDITOR=nano
            elif [ -f "$(which vim)" ];   then
                EDITOR=vim
            elif [ -f "$(which emacs)" ]; then
                EDITOR=emacs
            fi
        fi
        exec "$EDITOR" "${JOURNAL_FILE}"
    fi


    # Don't add a new date line
    if [ "$1" = "+" ]; then
        append="+"
        shift
    fi

    if [ "$1" = "-" ]; then
            stdin="-"
            shift
    fi


    if [ -z "$stdin" ]; then
        msg="$@"
    else
        msg=""
        while read line; do
            msg=$(printf "%s\n%s" "$msg" "$line")
        done
    fi

    msg="$(printf %s "$msg" | sed 's|^|\t|g')"


    if [ -z "$msg" ] && [ -z "$append" ]; then
        if [ ! -f ${JOURNAL_FILE} ]; then
            exec usage
        else
            exec "${VIEWER}" -- "${JOURNAL_FILE}"
        fi
    fi

    if [ -z "$append" ]; then
        printf "\n%s:\n\n" "$(date -R)" >> ${JOURNAL_FILE}
    fi

    printf "%s\n" "$msg" >> ${JOURNAL_FILE}



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: