-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-creating folders in logging path #2 #21
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,15 @@ | ||
# Variables in this helper should be set in the file sourcing the helper. | ||
# Required variables: | ||
# - path_option & default_path | ||
# - name_option & default_name | ||
|
||
get_path() { | ||
get_tmux_option "$path_option" "$default_path" | ||
} | ||
|
||
# `tmux save-buffer` command does not perform interpolation, so we're doing it | ||
# "manually" with `display-message` | ||
get_filename() { | ||
local name_template=$(get_tmux_option "$name_option" "$default_name") | ||
tmux display-message -p "$name_template" | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Big win! |
||
capture_pane() { | ||
local file="$(get_path)/$(get_filename)" | ||
local capture_scope=$1 | ||
if [ $capture_scope == "History" ]; then | ||
local file=$(tmux display-message -p "$save_complete_history_full_filename") | ||
local path=$(tmux display-message -p "$save_complete_history_path") | ||
mkdir -p "$path" | ||
local history_limit="$(tmux display-message -p -F "#{history_limit}")" | ||
tmux capture-pane -J -S "-${history_limit}" -p > "$file" | ||
elif [[ $capture_scope == "Screen capture" ]]; then | ||
local file=$(tmux display-message -p "$screen_capture_full_filename") | ||
local path=$(tmux display-message -p "$screen_capture_path") | ||
mkdir -p "$path" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After your refactoring it seems as this function is unnecessarily doing 2 things: capturing history and doing screen capture. Would it make things simpler if this one was split into two functions? With that we could get rid of this whole file because the functions would be kept in files where they're used.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it will be simpler than the current state. I will refactor this part |
||
tmux capture-pane -J -p > "$file" | ||
else | ||
# error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,21 +5,18 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
source "$CURRENT_DIR/variables.sh" | ||
source "$CURRENT_DIR/shared.sh" | ||
|
||
get_filename() { | ||
local logging_path="$(get_tmux_option "$logging_path_option" "$default_logging_path")" | ||
local logging_filename="$(get_tmux_option "$logging_filename_option" "$default_logging_filename")" | ||
echo "${logging_path}/${logging_filename}" | ||
} | ||
|
||
start_pipe_pane() { | ||
local filename="$(get_filename)" | ||
"$CURRENT_DIR/start_logging.sh" "$filename" | ||
display_message "Started logging to $filename" | ||
local file=$(tmux display-message -p "$logging_full_filename") | ||
local path=$(tmux display-message -p "$logging_path") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seing these 2 lines with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think about this part... Maybe you are right and extracting this code to external function will be a good decision |
||
mkdir -p "$path" | ||
"$CURRENT_DIR/start_logging.sh" "$file" | ||
display_message "Started logging to $logging_full_filename" | ||
} | ||
|
||
stop_pipe_pane() { | ||
tmux pipe-pane | ||
display_message "Ended logging to $(get_filename)" | ||
display_message "Ended logging to $logging_full_filename" | ||
} | ||
|
||
# returns a string unique to current pane | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that all the above functions are just one-liners now, how do you feel about just having them in the
main
function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good suggestion! I will make it in the second commit :)