You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit fixed the issue described in #5, by
1) writing all logs to a tmp file, including timestamp
2) sort all lines in tmp file by timestamp
3) output the sorted lines to stdout
4) since 1) is continued for all non-stoped containers, tail the tmp file (starting at the first unsorted line)
to avoid waisting hdd storage, every 10 seconds the tmpFile is emptied
fixes#5
Copy file name to clipboardExpand all lines: docker-fzf
+45-13Lines changed: 45 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -56,35 +56,67 @@ __docker_logs() (
56
56
return 0
57
57
fi
58
58
59
-
local resetColor="\033[39m\033[49m"
59
+
local resetColor="\x1b[39m\x1b[49m"
60
60
#list of 48 distinct colors
61
-
local allColors="\033[90m\n\033[92m\n\033[93m\n\033[94m\n\033[95m\n\033[96m\n\033[97m\n\033[30m\n\033[31m\n\033[32m\n\033[33m\n\033[34m\n\033[35m\n\033[36m\n\033[40m\033[90m\n\033[40m\033[91m\n\033[40m\033[92m\n\033[40m\033[94m\n\033[40m\033[95m\n\033[40m\033[96m\n\033[40m\033[97m\n\033[41m\033[90m\n\033[41m\033[93m\n\033[41m\033[95m\n\033[41m\033[97m\n\033[42m\033[90m\n\033[42m\033[93m\n\033[42m\033[97m\n\033[43m\033[90m\n\033[43m\033[93m\n\033[43m\033[97m\n\033[44m\033[91m\n\033[44m\033[92m\n\033[44m\033[93m\n\033[44m\033[95m\n\033[44m\033[97m\n\033[45m\033[93m\n\033[45m\033[97m\n\033[46m\033[90m\n\033[46m\033[91m\n\033[46m\033[92m\n\033[46m\033[93m\n\033[46m\033[96m\n\033[46m\033[97m\n\033[47m\033[90m\n\033[47m\033[95m\n\033[47m\033[96m\n"
61
+
local allColors="\x1b[90m\n\x1b[92m\n\x1b[93m\n\x1b[94m\n\x1b[95m\n\x1b[96m\n\x1b[97m\n\x1b[30m\n\x1b[31m\n\x1b[32m\n\x1b[33m\n\x1b[34m\n\x1b[35m\n\x1b[36m\n\x1b[40m\x1b[90m\n\x1b[40m\x1b[91m\n\x1b[40m\x1b[92m\n\x1b[40m\x1b[94m\n\x1b[40m\x1b[95m\n\x1b[40m\x1b[96m\n\x1b[40m\x1b[97m\n\x1b[41m\x1b[90m\n\x1b[41m\x1b[93m\n\x1b[41m\x1b[95m\n\x1b[41m\x1b[97m\n\x1b[42m\x1b[90m\n\x1b[42m\x1b[93m\n\x1b[42m\x1b[97m\n\x1b[43m\x1b[90m\n\x1b[43m\x1b[93m\n\x1b[43m\x1b[97m\n\x1b[44m\x1b[91m\n\x1b[44m\x1b[92m\n\x1b[44m\x1b[93m\n\x1b[44m\x1b[95m\n\x1b[44m\x1b[97m\n\x1b[45m\x1b[93m\n\x1b[45m\x1b[97m\n\x1b[46m\x1b[90m\n\x1b[46m\x1b[91m\n\x1b[46m\x1b[92m\n\x1b[46m\x1b[93m\n\x1b[46m\x1b[96m\n\x1b[46m\x1b[97m\n\x1b[47m\x1b[90m\n\x1b[47m\x1b[95m\n\x1b[47m\x1b[96m\n"
62
62
#list of `$count` number of distinct colors
63
63
local colors=$(echo -e "$allColors"| shuf -n $count)
64
64
65
-
local pids=()
65
+
local allPids=()
66
+
local writeToTmpFilePids=()
67
+
local tmpFile="/tmp/fzf-docker-logs-$(date +'%s')"
68
+
69
+
function_exit {
70
+
forpidin"${allPids[@]}";do
71
+
# ignore if process is not alive anymore
72
+
kill -9 $pid> /dev/null 2> /dev/null
73
+
done
74
+
75
+
test -e $tmpFile&& rm -f $tmpFile
76
+
}
77
+
trap _exit INT TERM SIGTERM
78
+
66
79
whileread -r name;do
67
80
# last color from list
68
81
local color=$(echo -e "$colors"| tail -n 1)
69
82
# update list - remove last color from list
70
83
colors=$(echo -e "$colors"| head -n -1)
71
84
72
85
# in bash, to get the pid for `docker logs` (so we can kill it in _exit), use `command1 > >(command2)` instead of `command1 | command2` - see https://stackoverflow.com/a/8048493/2732818
0 commit comments