mirror of
https://github.com/dchakro/brewlog.git
synced 2026-05-17 10:12:16 -07:00
v.0.1 upload
This commit is contained in:
parent
f34edf47cc
commit
b9216cebbc
3 changed files with 177 additions and 1 deletions
73
README.md
73
README.md
|
|
@ -1,2 +1,73 @@
|
|||
# brewlog
|
||||
ith brewlog you can run brew commands while simultanously logging to a file
|
||||
|
||||
### Why?
|
||||
|
||||
I wrote Brewlog to fulfill a shortcoming I felt [homebrew](https://brew.sh/) has had for a long time. I got the basic idea from [a very old issue on homebrew](https://github.com/Homebrew/legacy-homebrew/issues/10430).
|
||||
|
||||
### What can `brewlog` do ?
|
||||
|
||||
`brewlog` is simple solution that can:
|
||||
|
||||
+ log homebrew/linuxbrew activity (`STDOUT` and `STDERR`)
|
||||
+ as it is a new command, the user still retains the freedom to run `brew [command] [formula]` and not log it to the file
|
||||
+ tail the log file to display selected number of lines.
|
||||
+ archive the log file (when user invokes the appropriate command).
|
||||
+ a new log file is created the next time `brewlog` is invoked after archiving.
|
||||
|
||||
Now you'll be easily able to track the changes made by `brew upgrade`or `brew cleanup`.
|
||||
|
||||
|
||||
|
||||
### How to use
|
||||
|
||||
```sh
|
||||
curl -sSL 'install.sh' | bash
|
||||
|
||||
# Show help
|
||||
brewlog --help
|
||||
|
||||
# Running homebrew commands
|
||||
brewlog install ffmpeg
|
||||
brewlog info ffmpeg
|
||||
|
||||
# Even complex brew commands work with brewlog
|
||||
brewlog list --multiple --versions
|
||||
```
|
||||
|
||||
### Detailed usage
|
||||
|
||||
```
|
||||
brewlog - allows you to log your homebrew/linuxbrew operations to a file.
|
||||
Usage:
|
||||
brewlog [brew command] [arguments to homebrew]
|
||||
e.g.
|
||||
brewlog install ffmpeg, invokes "brew install ffmpeg" and writes output to a log file.
|
||||
|
||||
--help Show help
|
||||
--brew-help show brew commands (alias to "brew help")
|
||||
|
||||
OPTIONS:
|
||||
version Show brewlog version
|
||||
archive Archives the current log file as .xz
|
||||
tail [-n INT] Show the last "INT" lines from the log file.
|
||||
(default: last 15 lines)
|
||||
|
||||
Homebrew/Linuxbrew Function examples:
|
||||
brewlog install [formula] Install formula
|
||||
brewlog uninstall [formula] Uninstall formula
|
||||
brewlog deps [formula] Show dependencies for formula
|
||||
brewlog outdated Show outdated formulae
|
||||
brewlog upgrade [formula] Upgrade all (or entered) brew formula
|
||||
... ... ...
|
||||
Find out more homebrew commands by running "brew --help".
|
||||
```
|
||||
|
||||
|
||||
|
||||
**Note:**
|
||||
|
||||
+ Not to be confused with `brew log` which shows the commit history (similar to `git log`).
|
||||
+ I'm open to a new name, but for now as I personally don’t use `brew log`, I had no “merge conflicts” in my brain while assigning `brewlog` to achive my desired result of logging brew output :) [*IMHO* `brew history` *might have been a better name for* `brew log`]
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
90
brewlog.sh
Normal file
90
brewlog.sh
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#!/bin/bash
|
||||
|
||||
###########
|
||||
# author: robocopAlpha
|
||||
# https://github.com/robocopAlpha
|
||||
# Leave feedback: https://gist.github.com/robocopAlpha/3e9792b6e47c3648e725fb518a2dbf68
|
||||
#
|
||||
# Software provided as is without warranty.
|
||||
###########
|
||||
|
||||
# If needed modify the location of logfile
|
||||
LOGFILE="$HOME/Logs/brew.log"
|
||||
|
||||
|
||||
## Function definitions:
|
||||
|
||||
HELP()
|
||||
{
|
||||
printf 'brewlog - allows you to log your homebrew/linuxbrew operations to a file.
|
||||
Usage:
|
||||
brewlog [brew command] [arguments to homebrew]
|
||||
e.g.
|
||||
brewlog install ffmpeg, invokes "brew install ffmpeg" and writes output to a log file.
|
||||
|
||||
--help Show help
|
||||
--brew-help show brew commands (alias to "brew help")
|
||||
|
||||
OPTIONS:
|
||||
version Show brewlog version
|
||||
archive Archives the current log file as .xz
|
||||
tail [-n INT] Show the last "INT" lines from the log file.
|
||||
(default: last 15 lines)
|
||||
|
||||
Homebrew/Linuxbrew Function examples:
|
||||
brewlog install [formula] Install formula
|
||||
brewlog uninstall [formula] Uninstall formula
|
||||
brewlog deps [formula] Show dependencies for formula
|
||||
brewlog outdated Show outdated formulae
|
||||
brewlog upgrade [formula] Upgrade all (or entered) brew formula
|
||||
... ... ...
|
||||
Find out more homebrew commands by running "brew --help".
|
||||
';
|
||||
|
||||
}
|
||||
|
||||
VERSION()
|
||||
{
|
||||
printf 'brewlog v.0.1 - brewlog allows you to run homebrew commands while
|
||||
simultanously logging to a file
|
||||
|
||||
Follow the development: https://github.com/robocopAlpha/brewlog
|
||||
|
||||
';
|
||||
}
|
||||
VERSION
|
||||
|
||||
if [ ! -f "$LOGFILE" ] ; then
|
||||
# Creating brew.log
|
||||
echo "Creating $LOGFILE"
|
||||
mkdir -p "$(dirname "$LOGFILE")"
|
||||
touch "$LOGFILE"
|
||||
fi
|
||||
if [ "$1" == "--help" ]; then
|
||||
HELP
|
||||
elif [ "$1" == "--brew-help" ]; then
|
||||
brew help
|
||||
elif [ "$1" == "--brew-help" ]; then
|
||||
VERSION
|
||||
elif [ "$1" == "tail" ]; then
|
||||
if [ "$2" == "-n" ]; then
|
||||
# tail with specified number of lines
|
||||
tail -n "$3" "$LOGFILE"
|
||||
else
|
||||
# tail with 15 lines (default -n for tail is 10, I wanted more)
|
||||
tail -n 15 "$LOGFILE"
|
||||
fi
|
||||
elif [ "$1" == "archive" ]; then
|
||||
if [ -f "$LOGFILE" ] ; then
|
||||
# Archiving logfile i.e. brew.log is removed (will be created on next run)
|
||||
xz -vf $LOGFILE
|
||||
mv "${LOGFILE}.xz" "$LOGFILE-$(date +'%Y%m%d').xz"
|
||||
else
|
||||
echo "$LOGFILE doesn't exist"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "brew $* :: $(date)" | tee -a "$LOGFILE"
|
||||
# logs both STDOUT and STDERR to $LOGFILE
|
||||
$(which brew) "$@" 2>&1 | tee -a "$LOGFILE"
|
||||
fi
|
||||
15
install.sh
Normal file
15
install.sh
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
if [ -w /usr/local/bin ]; then
|
||||
curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/brewlog.sh' > /usr/local/bin/brewlog
|
||||
chmod +x /usr/local/bin/brewlog
|
||||
else
|
||||
sudo -s
|
||||
if [ -w /usr/local/bin ]; then
|
||||
curl -sSL 'https://raw.githubusercontent.com/robocopAlpha/brewlog/master/brewlog.sh' > /usr/local/bin/brewlog
|
||||
chmod +x /usr/local/bin/brewlog
|
||||
exit
|
||||
sudo -k
|
||||
else
|
||||
echo "cannot write to /usr/local/bin".
|
||||
exit 1;
|
||||
fi
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue