Skip to content

Instantly share code, notes, and snippets.

@solidnerd
Last active May 17, 2017 03:38
Show Gist options
  • Select an option

  • Save solidnerd/feaa8f1669df39a62cb0b88040d00667 to your computer and use it in GitHub Desktop.

Select an option

Save solidnerd/feaa8f1669df39a62cb0b88040d00667 to your computer and use it in GitHub Desktop.

Revisions

  1. solidnerd revised this gist May 17, 2017. 2 changed files with 86 additions and 1 deletion.
    21 changes: 20 additions & 1 deletion demo.sh
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -1 +1,20 @@
    test
    #!/bin/bash
    # Copyright 2016 The Kubernetes Authors.
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    # http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.

    . $(dirname ${BASH_SOURCE})/util.sh


    desc "Run echo"
    run "echo HelloWorld"
    66 changes: 66 additions & 0 deletions util.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    #!/bin/bash
    # Copyright 2016 The Kubernetes Authors All rights reserved.
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    # http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.

    readonly reset=$(tput sgr0)
    readonly green=$(tput bold; tput setaf 2)
    readonly yellow=$(tput bold; tput setaf 3)
    readonly blue=$(tput bold; tput setaf 6)

    function desc() {
    maybe_first_prompt
    echo "$blue# $@$reset"
    prompt
    }

    function prompt() {
    echo -n "$yellow\$ $reset"
    }

    started=""
    function maybe_first_prompt() {
    if [ -z "$started" ]; then
    prompt
    started=true
    fi
    }

    function run() {
    maybe_first_prompt
    rate=25
    if [ -n "$DEMO_RUN_FAST" ]; then
    rate=1000
    fi
    echo "$green$1$reset" | pv -qL $rate
    if [ -n "$DEMO_RUN_FAST" ]; then
    sleep 0.5
    fi
    eval "$1"
    r=$?
    read -d '' -t 1 -n 10000 # clear stdin
    prompt
    if [ -z "$DEMO_AUTO_RUN" ]; then
    read -s
    fi
    return $r
    }

    function relative() {
    for arg; do
    echo "$(realpath $(dirname $(which $0)))/$arg" | sed "s|$(realpath $(pwd))|.|"
    done
    }


    trap "echo" EXIT
  2. solidnerd created this gist May 17, 2017.
    1 change: 1 addition & 0 deletions demo.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    test