WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 45ba900

Browse files
committed
refactor: improve performance of all regex-based system commands
this commit also speeds up gitnow commands like: tag, logs, move, gitflow, github and bitbucket
1 parent 61edbe0 commit 45ba900

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

conf.d/gitnow.fish

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -355,19 +355,19 @@ function logs -d "Gitnow: Shows logs in a fancy way"
355355
set args $argv
356356
end
357357

358-
command git log $args --color --graph \
358+
LC_ALL=C command git log $args --color --graph \
359359
--pretty=format:"%Cred%h%C(reset) -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%C(reset) %C(brightmagenta dim)###%GK###%C(reset)%C(brightblack)@@%G?@@%C(reset)" --abbrev-commit \
360-
| command sed -E 's/@@@@//' \
361-
| command sed -E 's/@@([^"]*)@@/ (\1)/' \
362-
| command sed -E "s/###([^\"]*)###([^\"]*)\(G\)/"(command tput setaf 2)"\1/" \
363-
| command sed -E 's/###([^"]*)###/\1/' \
364-
| command sed -E 's/\(B\)/(bad signature)/' \
365-
| command sed -E 's/\(U\)/(good unknown validity signature)/' \
366-
| command sed -E 's/\(X\)/(good expired signature)/' \
367-
| command sed -E 's/\(Y\)/(good signature with expired key)/' \
368-
| command sed -E 's/\(R\)/(good signature with revoked key)/' \
369-
| command sed -E 's/\(E\)/(No checked signature)/' \
370-
| command sed -E 's/\(N\)//' \
360+
| LC_ALL=C command sed -E 's/@@@@//' \
361+
| LC_ALL=C command sed -E 's/@@([^"]*)@@/ (\1)/' \
362+
| LC_ALL=C command sed -E "s/###([^\"]*)###([^\"]*)\(G\)/"(command tput setaf 2)"\1/" \
363+
| LC_ALL=C command sed -E 's/###([^"]*)###/\1/' \
364+
| LC_ALL=C command sed -E 's/\(B\)/(bad signature)/' \
365+
| LC_ALL=C command sed -E 's/\(U\)/(good unknown validity signature)/' \
366+
| LC_ALL=C command sed -E 's/\(X\)/(good expired signature)/' \
367+
| LC_ALL=C command sed -E 's/\(Y\)/(good signature with expired key)/' \
368+
| LC_ALL=C command sed -E 's/\(R\)/(good signature with revoked key)/' \
369+
| LC_ALL=C command sed -E 's/\(E\)/(No checked signature)/' \
370+
| LC_ALL=C command sed -E 's/\(N\)//' \
371371
| command less -R
372372

373373
commandline -f repaint
@@ -463,8 +463,8 @@ function tag -d "Gitnow: Tag commits following Semver"
463463
return
464464
end
465465

466-
set -l x (echo $vstr | awk -F '.' '{print $1}')
467-
set -l prefix (echo $v_latest | awk -F "$vstr" '{print $1}')
466+
set -l x (echo $vstr | LC_ALL=C command awk -F '.' '{print $1}')
467+
set -l prefix (echo $v_latest | LC_ALL=C command awk -F "$vstr" '{print $1}')
468468
set x (__gitnow_increment_number $x)
469469
set -l xyz "$prefix$x.0.0"
470470

@@ -490,9 +490,9 @@ function tag -d "Gitnow: Tag commits following Semver"
490490
return
491491
end
492492

493-
set -l x (echo $vstr | awk -F '.' '{print $1}')
494-
set -l y (echo $vstr | awk -F '.' '{print $2}')
495-
set -l prefix (echo $v_latest | awk -F "$vstr" '{print $1}')
493+
set -l x (echo $vstr | LC_ALL=C command awk -F '.' '{print $1}')
494+
set -l y (echo $vstr | LC_ALL=C command awk -F '.' '{print $2}')
495+
set -l prefix (echo $v_latest | LC_ALL=C command awk -F "$vstr" '{print $1}')
496496
set y (__gitnow_increment_number $y)
497497
set -l xyz "$prefix$x.$y.0"
498498

@@ -518,13 +518,13 @@ function tag -d "Gitnow: Tag commits following Semver"
518518
return
519519
end
520520

521-
set -l x (echo $vstr | awk -F '.' '{print $1}')
522-
set -l y (echo $vstr | awk -F '.' '{print $2}')
523-
set -l z (echo $vstr | awk -F '.' '{print $3}')
524-
set -l s (echo $z | awk -F '-' '{print $1}')
521+
set -l x (echo $vstr | LC_ALL=C command awk -F '.' '{print $1}')
522+
set -l y (echo $vstr | LC_ALL=C command awk -F '.' '{print $2}')
523+
set -l z (echo $vstr | LC_ALL=C command awk -F '.' '{print $3}')
524+
set -l s (echo $z | LC_ALL=C command awk -F '-' '{print $1}')
525525

526526
if __gitnow_is_number $s
527-
set -l prefix (echo $v_latest | awk -F "$vstr" '{print $1}')
527+
set -l prefix (echo $v_latest | LC_ALL=C command awk -F "$vstr" '{print $1}')
528528
set s (__gitnow_increment_number $s)
529529
set -l xyz "$prefix$x.$y.$s"
530530

functions/__gitnow_functions.fish

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ end
1515

1616
# adapted from https://gist.github.com/oneohthree/f528c7ae1e701ad990e6
1717
function __gitnow_slugify
18-
echo $argv | command iconv -t ascii//TRANSLIT | command sed -E 's/[^a-zA-Z0-9\-]+/_/g' | command sed -E 's/^(-|_)+|(-|_)+$//g'
18+
echo $argv | LC_ALL=C command iconv -t ascii//TRANSLIT | LC_ALL=C command sed -E 's/[^a-zA-Z0-9\-]+/_/g' | LC_ALL=C command sed -E 's/^(-|_)+|(-|_)+$//g'
1919
end
2020

2121
function __gitnow_clone_repo
@@ -25,11 +25,11 @@ function __gitnow_clone_repo
2525
if test -n "$repo"
2626
set -l ok 1
2727

28-
if echo $repo | command grep -q -E '^[\%S].+'
28+
if echo $repo | LC_ALL=C command grep -q -E '^[\%S].+'
2929
set -l user (command git config --global user.$platform)
3030

3131
if test -n "$user"
32-
set -l repor (echo $repo | command sed -e "s/^%S/$user/")
32+
set -l repor (echo $repo | LC_ALL=C command sed -e "s/^%S/$user/")
3333
set repo $repor
3434
else
3535
set ok 0
@@ -97,7 +97,7 @@ function __gitnow_clone_params
9797
if count $argv >/dev/null
9898
if test (count $argv) -gt 1
9999
set repo $argv[1]/$argv[2]
100-
else if echo $argv | command grep -q -E '^([a-zA-Z0-9\_\-]+)\/([a-zA-Z0-9\_\-]+)$'
100+
else if echo $argv | LC_ALL=C command grep -q -E '^([a-zA-Z0-9\_\-]+)\/([a-zA-Z0-9\_\-]+)$'
101101
set repo $argv
102102
else
103103
set repo "%S/$argv"
@@ -130,7 +130,7 @@ function __gitnow_current_branch_name
130130
end
131131

132132
function __gitnow_current_branch_list
133-
command git branch --list --no-color | sed -E "s/^(\*?[ \t]*)//g" 2>/dev/null
133+
command git branch --list --no-color | LC_ALL=C command sed -E "s/^(\*?[ \t]*)//g" 2>/dev/null
134134
end
135135

136136
function __gitnow_current_remote
@@ -158,15 +158,15 @@ end
158158

159159
function __gitnow_get_latest_semver_release_tag
160160
for tg in (__gitnow_get_tags_ordered)
161-
if echo $tg | grep -qE '^v?([0-9]+).([0-9]+).([0-9]+)$'
161+
if echo $tg | LC_ALL=C command grep -qE '^v?([0-9]+).([0-9]+).([0-9]+)$'
162162
echo $tg 2>/dev/null
163163
break
164164
end
165165
end
166166
end
167167

168168
function __gitnow_increment_number -a strv
169-
command echo $strv | awk '
169+
command echo $strv | LC_ALL=C command awk '
170170
function increment(val) {
171171
if (val ~ /[0-9]+/) { return val + 1 }
172172
return val
@@ -176,13 +176,13 @@ function __gitnow_increment_number -a strv
176176
end
177177

178178
function __gitnow_get_valid_semver_release_value -a tagv
179-
command echo $tagv | command sed -n 's/^v\\{0,1\\}\([0-9].[0-9].[0-9]*\)\([}]*\)/\1/p' 2>/dev/null
179+
command echo $tagv | LC_ALL=C command sed -n 's/^v\\{0,1\\}\([0-9].[0-9].[0-9]*\)\([}]*\)/\1/p' 2>/dev/null
180180
end
181181

182182
function __gitnow_get_valid_semver_prerelease_value -a tagv
183-
command echo $tagv | command sed -n 's/^v\\{0,1\\}\([0-9].[0-9].[0-9]-[a-zA-Z0-9\-_.]*\)\([}]*\)/\1/p' 2>/dev/null
183+
command echo $tagv | LC_ALL=C command sed -n 's/^v\\{0,1\\}\([0-9].[0-9].[0-9]-[a-zA-Z0-9\-_.]*\)\([}]*\)/\1/p' 2>/dev/null
184184
end
185185

186186
function __gitnow_is_number -a strv
187-
command echo -n $strv | command grep -qE '^([0-9]+)$'
187+
command echo -n $strv | LC_ALL=C command grep -qE '^([0-9]+)$'
188188
end

0 commit comments

Comments
 (0)