Skip to content
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 #20

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion scripts/capture_pane_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
# - name_option & default_name

get_path() {
get_tmux_option "$path_option" "$default_path"
local path_template=$(get_tmux_option "$path_option" "$default_path")
local check_folder=$(tmux display-message -p "$path_template")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this line do? Why can't you just use path_template variable on the 2 lines below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason of this is that path_template contains "%Y-%m-%d" which we need to convert real values. It can be done only through tmux display-message because bash doesn't know about this anything

mkdir -p "${check_folder}"
echo "${check_folder}"
}

# `tmux save-buffer` command does not perform interpolation, so we're doing it
Expand Down
14 changes: 8 additions & 6 deletions scripts/toggle_logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

source "$CURRENT_DIR/variables.sh"
source "$CURRENT_DIR/shared.sh"
source "$CURRENT_DIR/capture_pane_helpers.sh"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The helpers in this file should only be included in files that handle "capture pane" features. If get_path helper is now needed in more places then maybe:

  • rename capture_pane_helpers.sh to be more generic
  • or create a separate helpers file just for get_path function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking at this more I think this would be clean:

  • create a separate helpers file for get_path
  • this new helpers file would be sourced in scripts/toggle_logging.sh and in scripts/capture_pane_helpers.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will think about it


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}"
}
# Functions defined in capture_pane_helpers are customized via below variables.
default_path="$default_logging_path"
default_name="$default_logging_filename"

path_option="$logging_path_option"
name_option="$logging_filename_option"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just reviewed how and why are these variables defined. I must say it was a lousy decision on my part to set this "global state" that is then used implicitly in functions defined in capture_pane_helpers.sh.

If you have a suggestion how to refactor this, that would be welcome. I think we just want to pass all arguments to functions explicitly. For example, instead of just get_path it would be ok to have get_path "$logging_path_option" "$default_logging_path"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wanna refactor this, let's do it in a separate PR. No need to do all at once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the advice. I will create separate PR for refactoring this


start_pipe_pane() {
local filename="$(get_filename)"
local filename="$(get_path)/$(get_filename)"
"$CURRENT_DIR/start_logging.sh" "$filename"
display_message "Started logging to $filename"
}
Expand Down