Skip to content

Commit 2a4e2e5

Browse files
committed
Refactor: extract function to remove status from diff line (#464)
1 parent 61d3192 commit 2a4e2e5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

bin/git-forgit

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ _forgit_reflog() {
232232
return $fzf_exit_code
233233
}
234234

235+
_forgit_remove_status_from_diff_line() {
236+
# Remove the status prefix from a diff line, e.g.
237+
# [M] somefile
238+
# becomes
239+
# somefile
240+
sed 's/^[[:space:]]*\[[A-Z0-9]*\][[:space:]]*//'
241+
}
242+
235243
_forgit_get_files_from_diff_line() {
236244
# Construct a null-terminated list of the filenames
237245
# The input looks like one of these lines:
@@ -244,13 +252,13 @@ _forgit_get_files_from_diff_line() {
244252
# oldfile\0
245253
# We have to do a two-step sed -> tr pipe because OSX's sed implementation does
246254
# not support the null-character directly.
247-
sed 's/^[[:space:]]*\[[A-Z0-9]*\][[:space:]]*//' | sed 's/ -> /\n/' | tr '\n' '\0'
255+
_forgit_remove_status_from_diff_line | sed 's/ -> /\n/' | tr '\n' '\0'
248256
}
249257

250258
_forgit_get_single_file_from_diff_line() {
251259
# Similar to the function above, but only gets a single file from a single line
252260
# Gets the new name of renamed files
253-
sed 's/^[[:space:]]*\[[A-Z0-9]*\][[:space:]]*//' | sed 's/.*-> //'
261+
_forgit_remove_status_from_diff_line | sed 's/.*-> //'
254262
}
255263

256264
_forgit_exec_diff() {

0 commit comments

Comments
 (0)