-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from BartSte/develop
Develop
- Loading branch information
Showing
7 changed files
with
95 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
################################################################################ | ||
# Logger | ||
# | ||
# Logs messages to the file at `FZF_HELP_LOG_PATH`. If the variable is not set, | ||
# the log file will be created at `~/.local/state/fzf-help.log`. The log file | ||
# will be truncated to the last `FZF_HELP_LOG_LINES` lines (default 10000). | ||
fzf_help_log() { | ||
local message fzf_help_log_path fzf_help_log_lines | ||
|
||
message=$1 | ||
fzf_help_log_path=${FZF_HELP_LOG_PATH:-~/.local/state/fzf-help.log} | ||
fzf_help_log_lines=${FZF_HELP_LOG_LINES:-10000} | ||
|
||
_fifo_log "$fzf_help_log_path" "$fzf_help_log_lines" "$message" | ||
} | ||
|
||
################################################################################ | ||
# _fifo_log | ||
# | ||
# Appends messages to the log file at `path`. If the file does not exist, it | ||
# will be created. If the number of lines in the log file exceeds the value of | ||
# `max_lines` then the log file will be truncated to the last `max_lines` lines. | ||
################################################################################ | ||
_fifo_log() { | ||
local path max_lines message | ||
|
||
path=$1 | ||
max_lines=$2 | ||
message=$3 | ||
|
||
if [ ! -f "$path" ]; then | ||
mkdir -p "$(dirname "$path")" | ||
touch "$path" | ||
fi | ||
|
||
echo "$message" >> "$path" | ||
|
||
if grep -E "^/dev/(null|stdout|stderr)$" <<< "$path" ; then | ||
return | ||
fi | ||
|
||
if [ $(wc -l < "$path") -gt "$max_lines" ]; then | ||
tail -n "$max_lines" "$path" > "$path".tmp | ||
mv "$path".tmp "$path" | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
name=$1 | ||
tmpdir=$(dirname "$(mktemp -u)") | ||
file="$tmpdir/$name" | ||
touch "$file" | ||
echo "$file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ setup_suite() { | |
unset FZF_HELP_SYNTAX | ||
unset CLI_OPTIONS_CMD | ||
unset HELP_MESSAGE_CMD | ||
unset HELP_MESSAGE_RC | ||
} | ||
|