-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatlog
More file actions
executable file
·63 lines (53 loc) · 1.46 KB
/
catlog
File metadata and controls
executable file
·63 lines (53 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
CRON_LOG_FILE="$XDG_DATA_HOME/cron/cron.log"
QTILE_LOG_FILE="$XDG_DATA_HOME/qtile/qtile.log"
_usage() {
echo "catlog [options] <file> [context]"
echo
echo "Options:"
echo " -f, --follow, f, follow Run 'tail -f' on the log file instead of 'cat'."
echo
echo "Context:"
echo "When --follow is specified"
echo " [N] The number of lines back from the end of the file to start printing from."
echo " Use 0 to start from the beginning of the file."
echo
echo "<file> may be a path or a 'known log file'"
echo "Known log files:"
echo " cron $XDG_DATA_HOME/cron/cron.log"
echo " qtile $XDG_DATA_HOME/qtile/qtile.log"
exit 0
}
catlog() {
local follow=0
local cmd=""
local log=""
local lines=""
case "$1" in
"-h" | "--help" | "h" | "help" ) _usage
esac
case "$1" in
"-f" | "f" | "follow" )
shift; follow=1
cmd+="tail -f "
;;
* ) cmd+="bat " ;;
esac
case "$1" in
"cron" )
shift
[[ $follow -eq 0 ]] && cmd+="--color never "
lines="${1:-50}"
log="$CRON_LOG_FILE"
;;
"qtile" )
shift
lines="${1:-100}"
log="$QTILE_LOG_FILE"
;;
* ) log="$1" ;;
esac
[[ $follow -eq 1 ]] && cmd+="--lines=$lines"
eval "$cmd" "$log"
}
catlog "$@"