Skip to content

Instantly share code, notes, and snippets.

@alexsancho
Created December 14, 2011 22:13
Show Gist options
  • Select an option

  • Save alexsancho/1478807 to your computer and use it in GitHub Desktop.

Select an option

Save alexsancho/1478807 to your computer and use it in GitHub Desktop.

Revisions

  1. alexsancho revised this gist Dec 14, 2011. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions log.sh
    Original file line number Diff line number Diff line change
    @@ -70,10 +70,8 @@ function _main_()
    esac
    done

    if [[ $growl ]]; then
    if [[ $(which growlnotify) ]]; then
    growlnotify "$title" --appIcon "Terminal" --message "$response"
    fi
    if [[ $growl && $(which growlnotify) ]]; then
    growlnotify "$title" --appIcon "Terminal" --message "$response"
    else
    echo -e$newline $response
    fi
  2. alexsancho revised this gist Dec 14, 2011. 1 changed file with 61 additions and 62 deletions.
    123 changes: 61 additions & 62 deletions log.sh
    Original file line number Diff line number Diff line change
    @@ -5,81 +5,80 @@
    # Version: 1.0
    # Date: 18.10.2011
    # Author: (c) by Alex Sancho - <alex@alexsancho.name>
    #
    # Notes: Display a message.
    #
    # Notes: Display a message.
    #####################################################################

    function usage()
    {
    prname=$(basename $0)
    log "$prname: Move filenames to lowercase"
    log "Usage: $prname [-s] [-e] [-w] [-n] [-g] [-t] <string>"
    log "Examp: $prname -w \"this is a warning!!\""
    log "Options:"
    log " $prname [-s] displays a success message"
    log " $prname -e displays an error message"
    log " $prname -w displays a warning message"
    log " $prname -n displays a warning message using -n as an echo argument"
    log " $prname -g displays a message using growlnotify"
    log " $prname -t sets the title of growl alert"
    prname=$(basename $0)
    log "$prname: Display a message."
    log "Usage: $prname [-s] [-e] [-w] [-n] [-g] [-t] <string>"
    log "Examp: $prname -w \"this is a warning!!\""
    log "Options:"
    log " $prname [-s] displays a success message"
    log " $prname -e displays an error message"
    log " $prname -w displays a warning message"
    log " $prname -n displays a warning message using -n as an echo argument"
    log " $prname -g displays a message using growlnotify"
    log " $prname -t sets the title of growl alert"
    }

    function _main_()
    {
    local response="" newline="" growl="" title=""
    local response="" newline="" growl="" title=""

    [[ -n 1 ]] || return 0;
    [[ -n 1 ]] || return 0;

    if [[ $# -eq 1 ]]; then
    response="\033[00;37m$1\033[00m"
    fi
    if [[ $# -eq 1 ]]; then
    response="\033[00;37m$1\033[00m"
    fi

    while getopts ":s:e:w:n:g:t:h[-help]:" optname
    do
    case "$optname" in
    h | -help)
    usage
    exit 2
    ;;
    s)
    response="\033[00;32m$OPTARG\033[00m"
    ;;
    e)
    response="\033[00;31m$OPTARG\033[00m"
    ;;
    w)
    response="\033[0;35m$OPTARG\033[00m"
    ;;
    n)
    response="\033[00;37m$OPTARG\033[00m"
    newline=n
    ;;
    t)
    title="$OPTARG"
    ;;
    g)
    growl=1
    response="$OPTARG"
    ;;
    \?)
    $0 -w "Invalid option: -$OPTARG" >&2
    ;;
    :)
    $0 -e "Option -$OPTARG requires an argument." >&2
    exit 1
    ;;
    esac
    done
    while getopts ":s:e:w:g:t:nh[-help]:" optname
    do
    case "$optname" in
    h | -help)
    usage
    exit 0
    ;;
    s)
    response="\033[00;32m$OPTARG\033[00m"
    ;;
    e)
    response="\033[00;31m$OPTARG\033[00m"
    ;;
    w)
    response="\033[0;35m$OPTARG\033[00m"
    ;;
    n)
    newline=n
    ;;
    t)
    title="$OPTARG"
    ;;
    g)
    growl=1
    response="$OPTARG"
    ;;
    \?)
    $0 -w "Invalid option: -$OPTARG" >&2
    ;;
    :)
    $0 -e "Option -$OPTARG requires an argument." >&2
    exit 1
    ;;
    esac
    done

    if [[ $growl ]]; then
    if [[ $(which growlnotify) ]]; then
    growlnotify "$title" --appIcon "Terminal" --message "$response"
    fi
    else
    echo -e$newline $response
    fi
    if [[ $growl ]]; then
    if [[ $(which growlnotify) ]]; then
    growlnotify "$title" --appIcon "Terminal" --message "$response"
    fi
    else
    echo -e$newline $response
    fi

    return 0
    return 0
    }

    ## Run script...
  3. alexsancho renamed this gist Dec 14, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. alexsancho created this gist Dec 14, 2011.
    86 changes: 86 additions & 0 deletions snippet.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    #!/usr/bin/env bash
    #####################################################################
    # Program: log
    #####################################################################
    # Version: 1.0
    # Date: 18.10.2011
    # Author: (c) by Alex Sancho - <alex@alexsancho.name>
    #
    # Notes: Display a message.
    #####################################################################

    function usage()
    {
    prname=$(basename $0)
    log "$prname: Move filenames to lowercase"
    log "Usage: $prname [-s] [-e] [-w] [-n] [-g] [-t] <string>"
    log "Examp: $prname -w \"this is a warning!!\""
    log "Options:"
    log " $prname [-s] displays a success message"
    log " $prname -e displays an error message"
    log " $prname -w displays a warning message"
    log " $prname -n displays a warning message using -n as an echo argument"
    log " $prname -g displays a message using growlnotify"
    log " $prname -t sets the title of growl alert"
    }

    function _main_()
    {
    local response="" newline="" growl="" title=""

    [[ -n 1 ]] || return 0;

    if [[ $# -eq 1 ]]; then
    response="\033[00;37m$1\033[00m"
    fi

    while getopts ":s:e:w:n:g:t:h[-help]:" optname
    do
    case "$optname" in
    h | -help)
    usage
    exit 2
    ;;
    s)
    response="\033[00;32m$OPTARG\033[00m"
    ;;
    e)
    response="\033[00;31m$OPTARG\033[00m"
    ;;
    w)
    response="\033[0;35m$OPTARG\033[00m"
    ;;
    n)
    response="\033[00;37m$OPTARG\033[00m"
    newline=n
    ;;
    t)
    title="$OPTARG"
    ;;
    g)
    growl=1
    response="$OPTARG"
    ;;
    \?)
    $0 -w "Invalid option: -$OPTARG" >&2
    ;;
    :)
    $0 -e "Option -$OPTARG requires an argument." >&2
    exit 1
    ;;
    esac
    done

    if [[ $growl ]]; then
    if [[ $(which growlnotify) ]]; then
    growlnotify "$title" --appIcon "Terminal" --message "$response"
    fi
    else
    echo -e$newline $response
    fi

    return 0
    }

    ## Run script...
    _main_ "$@"