Skip to content

Commit

Permalink
[bash-timer] Added an automatic installer mechanism.
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeseekr committed Sep 18, 2020
1 parent c2e17d9 commit 4741e97
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@ Shows a human-readable execution time for every command run in bash.

## Installation

Add the following to the very bottom of your `~/.bash_rc`.
### Use the Installer

```bash
curl https://raw.githubusercontent.com/hopeseekr/bash-timer/v1.0.0/install | bash
```

### Manual

1. Download the files:

```bash
curl https://raw.githubusercontent.com/hopeseekr/bash-timer/v1.0.0/bash-timer.sh -o $HOME/.bash-timer.sh
echo "c2e66332be7fe055d684c47a8f68b56926f7b03703f9e0c0aca95dbe310ec7c3 $HOME/.bash-timer.sh" | sha256sum -c -

curl https://raw.githubusercontent.com/bash-timer/bash-timer/v1.0.0/assets/bash-preexec.sh -o $HOME/.bash-preexec.sh
echo "04947faeb7f735d37cce12d820a1766ce0eb8288b64ee119e3ca1b00c4ed69ebce $HOME/.bash-preexec.sh" | sha256sum -c -
```

2. Add the following to the very bottom of your `~/.bash_rc`.

```bash
# Bash Timer
# See https://github.com/hopeseekr/bash-timer
if [ ! -f ~/.bash-timer.sh ]; then
# Pull down our file from GitHub and write it to our home directory as a hidden file.
curl https://raw.githubusercontent.com/hopeseekr/bash-timer/master/bash-timer.sh -o ~/.bash-timer.sh
fi
[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh
[[ -f ~/.bash-timer.sh ]] && source ~/.bash-timer.sh

# Bash Preexec.
# See https://github.com/rcaloras/bash-preexec
# **WARNING:** This must be the last line of your .bashrc.
if [ ! -f ~/.bash-preexec.sh ]; then
curl https://raw.githubusercontent.com/bash-timer/bash-timer/master/assets/bash-preexec.sh -o ~/.bash-preexec.sh
fi
# Source our file at the end of our bash profile (e.g. ~/.bashrc, ~/.profile, or ~/.bash_profile)
[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh
```
Expand Down
File renamed without changes.
53 changes: 53 additions & 0 deletions install
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

if [ ! -f ~/.bash-timer.sh ]; then
# Pull down our file from GitHub and write it to our home directory as a hidden file.
curl https://raw.githubusercontent.com/hopeseekr/bash-timer/v1.0.0/bash-timer.sh -o $HOME/.bash-timer.sh

if [ $(builtin type -P "sha256sum" 2>&1) ]; then
echo "c2e66332be7fe055d684c47a8f68b56926f7b03703f9e0c0aca95dbe310ec7c2 $HOME/.bash-timer.sh" | sha256sum -c -
if [ $? -ne 0 ]; then
rm -v ~/.bash-timer.sh
echo ERROR!! Invalid shasum for .bash-timer.sh !!
echo ERROR!! It has been deleted. Please grab from https://github.com/hopeseekr/bash-timer/
exit 1
fi
fi
fi

if [ ! -f ~/.bash-preexec.sh ]; then
curl https://raw.githubusercontent.com/hopeseekr/bash-timer/v1.0.0/assets/bash-preexec.sh -o $HOME/.bash-preexec.sh

if [ $(builtin type -P "sha256sum" 2>&1) ]; then
echo "04947faeb7f735d37cce12d820a1766ce0eb8288b64ee119e3ca1b00c4ed69eb $HOME/.bash-preexec.sh" | sha256sum -c -
if [ $? -ne 0 ]; then
rm -v ~/.bash-preexec.sh
echo ERROR!! Invalid shasum for .bash-preexec.sh !!
echo ERROR!! It has been deleted. Please grab from https://github.com/hopeseekr/bash-timer/
exit 2
fi
fi
fi

if [ ! -f "${HOME}/.bashrc" ]; then
echo "ERROR: Could not find ~/.bashrc. You need to do a manual installation."
echo "See https://github.com/hopeseekr/bash-timer"
exit 3
fi

# Heredoc concatenation: https://stackoverflow.com/a/2954835/430062
cat << EOF >> "${HOME}/.bashrc"
# Bash Timer
# See https://github.com/hopeseekr/bash-timer
[[ -f ~/.bash-timer.sh ]] && source ~/.bash-timer.sh
# See https://github.com/rcaloras/bash-preexec
# **WARNING:** This must be the last line of your .bashrc.
# Source our file at the end of our bash profile (e.g. ~/.bashrc, ~/.profile, or ~/.bash_profile)
[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh
EOF

echo "Install succeeded!"
echo
echo "Now run"
echo " source ~/.bashrc"

0 comments on commit 4741e97

Please sign in to comment.