Skip to content

Instantly share code, notes, and snippets.

@dergachev
Last active September 28, 2016 14:56
Show Gist options
  • Save dergachev/5766167 to your computer and use it in GitHub Desktop.
Save dergachev/5766167 to your computer and use it in GitHub Desktop.

Revisions

  1. dergachev revised this gist Sep 25, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions prepend-timestamp.md
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ Would you prefer to see the following?

    Then simply append this snippet to your command, as follows:

    ```
    ```bash
    vagrant provision 2>&1 | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T.%L") + "\e[0m " + $_'
    ```

    @@ -48,7 +48,7 @@ vagrant up 2>&1 | prepend-timestamp

    Then do the following:

    ```
    ```bash
    ##
    ## Creates a ~/bin folder and ensure it's in $PATH;
    ## via http://askubuntu.com/a/247422/194314
  2. dergachev revised this gist Sep 25, 2013. 1 changed file with 19 additions and 16 deletions.
    35 changes: 19 additions & 16 deletions prepend-timestamp.md
    Original file line number Diff line number Diff line change
    @@ -4,26 +4,29 @@ Shell snippet that prepends a nice to a command's output.

    For example, here's the (snipped) output of `vagrant provision`:

    > Successfully installed bundler-1.3.5
    > 1 gem installed
    > Using rmagick (2.13.2)
    > Using bundler (1.3.5)
    > Use `bundle show [gemname]` to see where a bundled gem is installed.
    > [default] Running provisioner: shell...
    > [default] Running: inline script
    ```
    Successfully installed bundler-1.3.5
    1 gem installed
    Using rmagick (2.13.2)
    Using bundler (1.3.5)
    Use `bundle show [gemname]` to see where a bundled gem is installed.
    [default] Running provisioner: shell...
    [default] Running: inline script
    ```

    Would you prefer to see the following?

    > **18:32:05.055** Successfully installed bundler-1.3.5
    > **18:32:05.055** 1 gem installed
    > **18:32:05.282** Using rmagick (2.13.2)
    > **18:32:05.282** Using bundler (1.3.5)
    > **18:32:05.285** Use `bundle show [gemname]` to see where a bundled gem is installed.
    > **18:32:05.291** [default] Running provisioner: shell...
    > **18:32:05.789** [default] Running: inline script
    Then simply modify the above command as follows:
    ```
    18:32:05.055 Successfully installed bundler-1.3.5
    18:32:05.055 1 gem installed
    18:32:05.282 Using rmagick (2.13.2)
    18:32:05.282 Using bundler (1.3.5)
    18:32:05.285 Use `bundle show [gemname]` to see where a bundled gem is installed.
    18:32:05.291 [default] Running provisioner: shell...
    18:32:05.789 [default] Running: inline script
    ```

    Then simply append this snippet to your command, as follows:

    ```
    vagrant provision 2>&1 | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T.%L") + "\e[0m " + $_'
  3. dergachev revised this gist Sep 25, 2013. 1 changed file with 14 additions and 14 deletions.
    28 changes: 14 additions & 14 deletions prepend-timestamp.md
    Original file line number Diff line number Diff line change
    @@ -4,23 +4,23 @@ Shell snippet that prepends a nice to a command's output.

    For example, here's the (snipped) output of `vagrant provision`:

    > Successfully installed bundler-1.3.5
    > 1 gem installed
    > Using rmagick (2.13.2)
    > Using bundler (1.3.5)
    > Use `bundle show [gemname]` to see where a bundled gem is installed.
    > [default] Running provisioner: shell...
    > [default] Running: inline script
    > Successfully installed bundler-1.3.5
    > 1 gem installed
    > Using rmagick (2.13.2)
    > Using bundler (1.3.5)
    > Use `bundle show [gemname]` to see where a bundled gem is installed.
    > [default] Running provisioner: shell...
    > [default] Running: inline script
    Would you prefer to see the following?

    > **18:32:05.055** Successfully installed bundler-1.3.5
    > **18:32:05.055** 1 gem installed
    > **18:32:05.282** Using rmagick (2.13.2)
    > **18:32:05.282** Using bundler (1.3.5)
    > **18:32:05.285** Use `bundle show [gemname]` to see where a bundled gem is installed.
    > **18:32:05.291** [default] Running provisioner: shell...
    > **18:32:05.789** [default] Running: inline script
    > **18:32:05.055** Successfully installed bundler-1.3.5
    > **18:32:05.055** 1 gem installed
    > **18:32:05.282** Using rmagick (2.13.2)
    > **18:32:05.282** Using bundler (1.3.5)
    > **18:32:05.285** Use `bundle show [gemname]` to see where a bundled gem is installed.
    > **18:32:05.291** [default] Running provisioner: shell...
    > **18:32:05.789** [default] Running: inline script
    Then simply modify the above command as follows:

  4. dergachev revised this gist Sep 25, 2013. 1 changed file with 15 additions and 12 deletions.
    27 changes: 15 additions & 12 deletions prepend-timestamp.md
    Original file line number Diff line number Diff line change
    @@ -2,22 +2,25 @@

    Shell snippet that prepends a nice to a command's output.

    For example, here's the (snipped) output of `VAGRANT_LOG=debug vagrant provision`:
    For example, here's the (snipped) output of `vagrant provision`:

    > INFO environment: Home path: /Users/dergachev/.vagrant.d
    > WARN environment: No local data path is set. Local data cannot be stored.
    > WARN environment: In a bundler environment, not loading environment plugins!
    > INFO environment: Running hook: environment_load
    > INFO environment: Initializing config...
    > Successfully installed bundler-1.3.5
    > 1 gem installed
    > Using rmagick (2.13.2)
    > Using bundler (1.3.5)
    > Use `bundle show [gemname]` to see where a bundled gem is installed.
    > [default] Running provisioner: shell...
    > [default] Running: inline script
    Would you prefer to see the following?

    > **17:47:19:938** INFO environment: Home path: /Users/dergachev/.vagrant.d
    > **17:47:19:939** WARN environment: No local data path is set. Local data cannot be stored.
    > **17:47:19:939** WARN environment: In a bundler environment, not loading environment plugins!
    > **17:47:19:939** INFO environment: Running hook: environment_load
    > **17:47:19:948** INFO environment: Initializing config...
    > **18:32:05.055** Successfully installed bundler-1.3.5
    > **18:32:05.055** 1 gem installed
    > **18:32:05.282** Using rmagick (2.13.2)
    > **18:32:05.282** Using bundler (1.3.5)
    > **18:32:05.285** Use `bundle show [gemname]` to see where a bundled gem is installed.
    > **18:32:05.291** [default] Running provisioner: shell...
    > **18:32:05.789** [default] Running: inline script
    Then simply modify the above command as follows:

  5. dergachev revised this gist Sep 25, 2013. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions prepend-timestamp.md
    Original file line number Diff line number Diff line change
    @@ -19,15 +19,16 @@ Would you prefer to see the following?
    > **17:47:19:948** INFO environment: Initializing config...

    Then simply pipe the command to ` | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T.%L") + "\e[0m " + $_'`, as follows:
    Then simply modify the above command as follows:


    ```
    VAGRANT_LOG=debug vagrant provision 2>&1 | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T.%L") + "\e[0m " + $_'
    vagrant provision 2>&1 | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T.%L") + "\e[0m " + $_'
    ```

    Keep in mind the following:

    * `2>&1` redirects stderr to stdout, which allows the script to work on it too.
    * `2>&1` redirects stderr to stdout (pipes only work on stdout)
    * `\e[33m` and `\e[0m` are terminal escape codes that make the text between them yellow
    * `%T` is HH:MM:SS and `%L` adds milliseconds in the time formatting command.

  6. dergachev revised this gist Sep 25, 2013. 1 changed file with 10 additions and 18 deletions.
    28 changes: 10 additions & 18 deletions prepend-timestamp.md
    Original file line number Diff line number Diff line change
    @@ -4,27 +4,19 @@ Shell snippet that prepends a nice to a command's output.

    For example, here's the (snipped) output of `VAGRANT_LOG=debug vagrant provision`:

    > INFO environment: Home path: /Users/dergachev/.vagrant.d
    > WARN environment: No local data path is set. Local data cannot be stored.
    > WARN environment: In a bundler environment, not loading environment plugins!
    > INFO environment: Running hook: environment_load
    > INFO environment: Initializing config...
    > INFO environment: Home path: /Users/dergachev/.vagrant.d
    > WARN environment: No local data path is set. Local data cannot be stored.
    > WARN environment: In a bundler environment, not loading environment plugins!
    > INFO environment: Running hook: environment_load
    > INFO environment: Initializing config...
    Would you prefer to see the following?

    > **17:47:19:938** INFO environment: Home path: /Users/dergachev/.vagrant.d
    > **17:47:19:939** WARN environment: No local data path is set. Local data cannot be stored.
    > **17:47:19:939** WARN environment: In a bundler environment, not loading environment plugins!
    > **17:47:19:939** INFO environment: Running hook: environment_load
    > **17:47:19:948** INFO environment: Initializing config...
    > **17:47:19:938** INFO environment: Home path: /Users/dergachev/.vagrant.d
    > **17:47:19:939** WARN environment: No local data path is set. Local data cannot be stored.
    > **17:47:19:939** WARN environment: In a bundler environment, not loading environment plugins!
    > **17:47:19:939** INFO environment: Running hook: environment_load
    > **17:47:19:948** INFO environment: Initializing config...

    Then simply pipe the command to ` | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T.%L") + "\e[0m " + $_'`, as follows:
  7. dergachev revised this gist Sep 25, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions prepend-timestamp.md
    Original file line number Diff line number Diff line change
    @@ -17,9 +17,13 @@ For example, here's the (snipped) output of `VAGRANT_LOG=debug vagrant provision
    Would you prefer to see the following?

    > **17:47:19:938** INFO environment: Home path: /Users/dergachev/.vagrant.d
    > **17:47:19:939** WARN environment: No local data path is set. Local data cannot be stored.
    > **17:47:19:939** WARN environment: In a bundler environment, not loading environment plugins!
    > **17:47:19:939** INFO environment: Running hook: environment_load
    > **17:47:19:948** INFO environment: Initializing config...

  8. dergachev revised this gist Sep 25, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions prepend-timestamp.md
    Original file line number Diff line number Diff line change
    @@ -5,9 +5,13 @@ Shell snippet that prepends a nice to a command's output.
    For example, here's the (snipped) output of `VAGRANT_LOG=debug vagrant provision`:

    > INFO environment: Home path: /Users/dergachev/.vagrant.d
    > WARN environment: No local data path is set. Local data cannot be stored.
    > WARN environment: In a bundler environment, not loading environment plugins!
    > INFO environment: Running hook: environment_load
    > INFO environment: Initializing config...
    Would you prefer to see the following?
  9. dergachev revised this gist Sep 25, 2013. 1 changed file with 18 additions and 10 deletions.
    28 changes: 18 additions & 10 deletions prepend-timestamp.md
    Original file line number Diff line number Diff line change
    @@ -2,19 +2,27 @@

    Shell snippet that prepends a nice to a command's output.

    ```
    17:47:19:938 INFO environment: Home path: /Users/dergachev/.vagrant.d
    17:47:19:939 WARN environment: No local data path is set. Local data cannot be stored.
    17:47:19:939 WARN environment: In a bundler environment, not loading environment plugins!
    17:47:19:939 INFO environment: Running hook: environment_load
    17:47:19:948 INFO environment: Initializing config...
    ```
    For example, here's the (snipped) output of `VAGRANT_LOG=debug vagrant provision`:

    > INFO environment: Home path: /Users/dergachev/.vagrant.d
    > WARN environment: No local data path is set. Local data cannot be stored.
    > WARN environment: In a bundler environment, not loading environment plugins!
    > INFO environment: Running hook: environment_load
    > INFO environment: Initializing config...
    Would you prefer to see the following?

    > **17:47:19:938** INFO environment: Home path: /Users/dergachev/.vagrant.d
    > **17:47:19:939** WARN environment: No local data path is set. Local data cannot be stored.
    > **17:47:19:939** WARN environment: In a bundler environment, not loading environment plugins!
    > **17:47:19:939** INFO environment: Running hook: environment_load
    > **17:47:19:948** INFO environment: Initializing config...

    To use it via copy and paste, just replace `vagrant provision` in the
    following snippet with your own command:
    Then simply pipe the command to ` | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T.%L") + "\e[0m " + $_'`, as follows:

    ```
    vagrant provision 2>&1 | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T.%L") + "\e[0m " + $_'
    VAGRANT_LOG=debug vagrant provision 2>&1 | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T.%L") + "\e[0m " + $_'
    ```

    Keep in mind the following:
  10. dergachev revised this gist Sep 25, 2013. 1 changed file with 40 additions and 10 deletions.
    50 changes: 40 additions & 10 deletions prepend-timestamp.md
    Original file line number Diff line number Diff line change
    @@ -1,31 +1,61 @@
    To use it via copy and paste, just modify the following:
    # prepend-timestamp

    Shell snippet that prepends a nice to a command's output.

    ```
    17:47:19:938 INFO environment: Home path: /Users/dergachev/.vagrant.d
    17:47:19:939 WARN environment: No local data path is set. Local data cannot be stored.
    17:47:19:939 WARN environment: In a bundler environment, not loading environment plugins!
    17:47:19:939 INFO environment: Running hook: environment_load
    17:47:19:948 INFO environment: Initializing config...
    ```
    vagrant provision 2>&1 | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T:%L") + "\e[0m " + $_'

    To use it via copy and paste, just replace `vagrant provision` in the
    following snippet with your own command:

    ```
    vagrant provision 2>&1 | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T.%L") + "\e[0m " + $_'
    ```

    Keep in mind the following:

    * `2>&1` redirects stderr to stdout, which allows the script to work on it too.
    * `\e[33m` and `\e[0m` are terminal escape codes that make the text between them yellow
    * `%T` is HH:MM:SS and `%L` adds milliseconds in the time formatting command.

    To install it:
    ## Installing the script

    Prefer to invoke the script in a friendlier way?

    ```bash
    vagrant up 2>&1 | prepend-timestamp
    ```
    mkdir ~/bin # see http://askubuntu.com/a/247422/194314

    Then do the following:

    ```
    ##
    ## Creates a ~/bin folder and ensure it's in $PATH;
    ## via http://askubuntu.com/a/247422/194314
    ##
    mkdir ~/bin
    cat - >> ~/.bashrc <<'EOT'
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
    fi
    EOT
    source ~/.bashrc
    ##
    ## Installs ~/bin/prepend-timestamp and makes it executable
    ##
    cat - > ~/bin/prepend-timestamp <<'EOT'
    #!/bin/sh
    ruby -ne 'puts "\e[33m" + Time.now().strftime("%T:%L") + "\e[0m " + $_'
    ruby -ne 'puts "\e[33m" + Time.now().strftime("%T.%L") + "\e[0m " + $_'
    EOT
    chmod u+x ~/bin/prepend-timestamp
    ```

    After installing it, use it like this:

    ```
    vagrant up 2>&1 | prepend-timestamp
    ```
    Done!
  11. dergachev revised this gist Sep 25, 2013. 2 changed files with 31 additions and 7 deletions.
    31 changes: 31 additions & 0 deletions prepend-timestamp.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    To use it via copy and paste, just modify the following:

    ```
    vagrant provision 2>&1 | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T:%L") + "\e[0m " + $_'
    ```

    To install it:

    ```
    mkdir ~/bin # see http://askubuntu.com/a/247422/194314
    cat - >> ~/.bashrc <<'EOT'
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
    fi
    EOT
    cat - > ~/bin/prepend-timestamp <<'EOT'
    #!/bin/sh
    ruby -ne 'puts "\e[33m" + Time.now().strftime("%T:%L") + "\e[0m " + $_'
    EOT
    chmod u+x ~/bin/prepend-timestamp
    ```

    After installing it, use it like this:

    ```
    vagrant up 2>&1 | prepend-timestamp
    ```
    7 changes: 0 additions & 7 deletions prepend-timestamp.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +0,0 @@
    # example usage as script:
    # vagrant up | bash prepend-timestamp.sh
    # or directly as a snippet:
    # vagrant up | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T") + "\e[0m " + $_'

    ruby -ne 'puts "\e[33m" + Time.now().strftime("%T") + "\e[0m " + $_'

  12. dergachev revised this gist Sep 24, 2013. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions prepend-timestamp.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    # example usage:
    # example usage as script:
    # vagrant up | bash prepend-timestamp.sh
    ruby -ne 'puts "\e[33m" + Time.now().strftime("%T") + "\e[0m " + $_'
    # or directly as a snippet:
    # vagrant up | ruby -ne 'puts "\e[33m" + Time.now().strftime("%T") + "\e[0m " + $_'

    ruby -ne 'puts "\e[33m" + Time.now().strftime("%T") + "\e[0m " + $_'

  13. dergachev renamed this gist Jun 12, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  14. dergachev revised this gist Jun 12, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion prepend-timestamps.sh
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,3 @@
    # example usage: vagrant up | bash prepend-timestamp.sh
    # example usage:
    # vagrant up | bash prepend-timestamp.sh
    ruby -ne 'puts "\e[33m" + Time.now().strftime("%T") + "\e[0m " + $_'
  15. dergachev created this gist Jun 12, 2013.
    2 changes: 2 additions & 0 deletions prepend-timestamps.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    # example usage: vagrant up | bash prepend-timestamp.sh
    ruby -ne 'puts "\e[33m" + Time.now().strftime("%T") + "\e[0m " + $_'