diff options
| author | Anton Bobov <abobov@gmail.com> | 2021-05-07 09:44:49 +0500 |
|---|---|---|
| committer | Anton Bobov <abobov@gmail.com> | 2021-05-07 10:10:39 +0500 |
| commit | f563df749c7638ac3c7d82ae6ab48895581c10b9 (patch) | |
| tree | 09f5abeb0173a4e858fb4d509cd85f6a5a9ed7ab | |
| parent | 91d03df8a6ea971f1adbc071fe1f4e056f0e7b36 (diff) | |
Updates.
| -rwxr-xr-x | diff-so-fancy | 92 | ||||
| -rwxr-xr-x | emojis | 91 |
2 files changed, 173 insertions, 10 deletions
diff --git a/diff-so-fancy b/diff-so-fancy index 8dc9a99..7d33a34 100755 --- a/diff-so-fancy +++ b/diff-so-fancy @@ -332,7 +332,7 @@ unshift @INC, bless \%fatpacked, $class; } # END OF FATPACK CODE -my $VERSION = "1.3.0"; +my $VERSION = "1.4.0"; ################################################################################# @@ -350,6 +350,7 @@ use warnings FATAL => 'all'; my $remove_file_add_header = 1; my $remove_file_delete_header = 1; my $clean_permission_changes = 1; +my $patch_mode = 0; my $manually_color_lines = 0; # Usually git/hg colorizes the lines, but for raw patches we use this my $change_hunk_indicators = git_config_boolean("diff-so-fancy.changeHunkIndicators","true"); my $strip_leading_indicators = git_config_boolean("diff-so-fancy.stripLeadingSymbols","true"); @@ -384,6 +385,18 @@ if ($args->{color_on}) { $color_forced = 1; } +if ($args->{debug}) { + show_debug_info(); + exit(); +} + +# `git add --patch` requires our output to match the number of lines from the +# input. So, when patch mode is active, we print out empty lines to pad our +# output to match any lines we've consumed. +if ($args->{patch}) { + $patch_mode = 1; +} + # We only process ARGV if we don't have STDIN if (!$has_stdin) { if ($args->{v} || $args->{version}) { @@ -511,6 +524,10 @@ sub do_dsf_stuff { $last_file_seen =~ s|^\w/||; # Remove a/ (and handle diff.mnemonicPrefix). $in_hunk = 0; + if ($patch_mode) { + # we are consuming one line, and the debt must be paid + print "\n"; + } ######################################## # Find the first file: --- a/README.md # ######################################## @@ -608,12 +625,18 @@ sub do_dsf_stuff { } elsif ($remove_file_add_header && $line =~ /^${ansi_color_regex}.*new file mode/) { # Don't print the line (i.e. remove it from the output); $last_file_mode = "add"; + if ($patch_mode) { + print "\n"; + } ###################################### # Remove any delete file permissions # ###################################### } elsif ($remove_file_delete_header && $line =~ /^${ansi_color_regex}deleted file mode/) { # Don't print the line (i.e. remove it from the output); $last_file_mode = "delete"; + if ($patch_mode) { + print "\n"; + } ################################ # Look for binary file changes # ################################ @@ -634,6 +657,10 @@ sub do_dsf_stuff { } my ($new_mode) = $next =~ m/new mode (\d+)/; + + if ($patch_mode) { + print "\n"; + } print "$last_file_seen changed file mode from $old_mode to $new_mode\n"; ############### @@ -812,11 +839,15 @@ sub in_unit_test { sub get_less_charset { my @less_char_vars = ("LESSCHARSET", "LESSCHARDEF", "LC_ALL", "LC_CTYPE", "LANG"); - foreach (@less_char_vars) { - return $ENV{$_} if defined $ENV{$_}; + foreach my $key (@less_char_vars) { + my $val = $ENV{$key}; + + if (defined $val) { + return ($key, $val); + } } - return ""; + return (); } sub should_print_unicode { @@ -826,7 +857,8 @@ sub should_print_unicode { } # Otherwise, assume we're piping to less(1) - my $less_charset = get_less_charset(); + my ($less_env_var, $less_charset) = get_less_charset(); + $less_charset //= ""; if ($less_charset =~ /utf-?8/i) { return 1; } @@ -876,16 +908,23 @@ sub strip_leading_indicators { if ($manually_color_lines) { if (defined($5) && $5 eq "+") { my $add_line_color = get_config_color("add_line"); - $line = $add_line_color . $line . $reset_color; + $line = $add_line_color . insert_reset_at_line_end($line); } elsif (defined($5) && $5 eq "-") { my $remove_line_color = get_config_color("remove_line"); - $line = $remove_line_color . $line . $reset_color; + $line = $remove_line_color . insert_reset_at_line_end($line); } } return $line; } +# Insert the color reset code at end of line, but before any newlines +sub insert_reset_at_line_end { + my $line = shift(); + $line =~ s/^(.*)([\n\r]+)?$/${1}${reset_color}${2}/; + return $line; +} + # Count the number of a given char in a string sub char_count { my ($needle,$str) = @_; @@ -1017,9 +1056,13 @@ diff -u one.txt two.txt | diff-so-fancy # Use d-s-f on unified diff output diff-so-fancy --colors # View the commands to set the recommended colors diff-so-fancy --set-defaults # Configure git-diff to use diff-so-fancy and suggested colors +diff-so-fancy --patch # Use diff-so-fancy in patch mode (interoperable with `git add --patch`) # Configure git to use d-s-f for *all* diff operations -git config --global core.pager \"diff-so-fancy | less --tabs=4 -RFX\"\n"; +git config --global core.pager \"diff-so-fancy | less --tabs=4 -RFX\" + +# Configure git to use d-s-f for `git add --patch` +git config --global interactive.diffFilter \"diff-so-fancy --patch\"\n"; return $out; } @@ -1226,4 +1269,37 @@ sub get_terminal_width { return $width; } +sub show_debug_info { + my @less = get_less_charset(); + my $git_ver = trim(`git --version`); + $git_ver =~ s/[^\d.]//g; + + print "Diff-so-fancy : v$VERSION\n"; + print "Git : v$git_ver\n"; + print "Perl : $^V\n"; + print "\n"; + + print "Terminal width : " . get_terminal_width() . "\n"; + print "Terminal \$LANG : " . $ENV{LANG} . "\n"; + print "\n"; + print "Supports Unicode: " . yes_no(should_print_unicode()) . "\n"; + print "Unicode Ruler : " . yes_no($use_unicode_dash_for_ruler) . "\n"; + print "\n"; + print "Less Charset Var: " . ($less[0] // "") . "\n"; + print "Less Charset : " . ($less[1] // "") . "\n"; + print "\n"; + print "Is Windows : " . yes_no(is_windows()) . "\n"; + print "Operating System: $^O\n"; +} + +sub yes_no { + my $val = shift(); + + if ($val) { + return "Yes"; + } else { + return "No"; + } +} + # vim: tabstop=4 shiftwidth=4 noexpandtab autoindent softtabstop=4 @@ -1,10 +1,96 @@ #!/bin/bash -sed -e '1,/^# EMOJI STARS HERE/ d' "$0" | fzf | awk '{print $1}' | xsel +set -e + +list() { + name="$1" + sed -n "/^# $name STARTS HERE$/,/^# $name ENDS HERE$/{//!p;}" "$0" | + fzf --no-sort --reverse | awk '{print $1}' | xsel +} + +name=EMOJI +while [[ $# -gt 0 ]] ; do + case "$1" in + -g|--git) + name=GITMOJI + ;; + esac + shift +done + +list $name exit 0 -# EMOJI STARS HERE +# curl -Ls https://github.com/carloscuesta/gitmoji/raw/master/src/data/gitmojis.json | jq -r '.gitmojis[] | "\(.emoji)\t\(.description) [\(.name)]"' +# GITMOJI STARTS HERE +🎨 Improve structure / format of the code. [art] +⚡️ Improve performance. [zap] +🔥 Remove code or files. [fire] +🐛 Fix a bug. [bug] +🚑️ Critical hotfix. [ambulance] +✨ Introduce new features. [sparkles] +📝 Add or update documentation. [memo] +🚀 Deploy stuff. [rocket] +💄 Add or update the UI and style files. [lipstick] +🎉 Begin a project. [tada] +✅ Add or update tests. [white-check-mark] +🔒️ Fix security issues. [lock] +🔖 Release / Version tags. [bookmark] +🚨 Fix compiler / linter warnings. [rotating-light] +🚧 Work in progress. [construction] +💚 Fix CI Build. [green-heart] +⬇️ Downgrade dependencies. [arrow-down] +⬆️ Upgrade dependencies. [arrow-up] +📌 Pin dependencies to specific versions. [pushpin] +👷 Add or update CI build system. [construction-worker] +📈 Add or update analytics or track code. [chart-with-upwards-trend] +♻️ Refactor code. [recycle] +➕ Add a dependency. [heavy-plus-sign] +➖ Remove a dependency. [heavy-minus-sign] +🔧 Add or update configuration files. [wrench] +🔨 Add or update development scripts. [hammer] +🌐 Internationalization and localization. [globe-with-meridians] +✏️ Fix typos. [pencil2] +💩 Write bad code that needs to be improved. [poop] +⏪️ Revert changes. [rewind] +🔀 Merge branches. [twisted-rightwards-arrows] +📦️ Add or update compiled files or packages. [package] +👽️ Update code due to external API changes. [alien] +🚚 Move or rename resources (e.g.: files, paths, routes). [truck] +📄 Add or update license. [page-facing-up] +💥 Introduce breaking changes. [boom] +🍱 Add or update assets. [bento] +♿️ Improve accessibility. [wheelchair] +💡 Add or update comments in source code. [bulb] +🍻 Write code drunkenly. [beers] +💬 Add or update text and literals. [speech-balloon] +🗃️ Perform database related changes. [card-file-box] +🔊 Add or update logs. [loud-sound] +🔇 Remove logs. [mute] +👥 Add or update contributor(s). [busts-in-silhouette] +🚸 Improve user experience / usability. [children-crossing] +🏗️ Make architectural changes. [building-construction] +📱 Work on responsive design. [iphone] +🤡 Mock things. [clown-face] +🥚 Add or update an easter egg. [egg] +🙈 Add or update a .gitignore file. [see-no-evil] +📸 Add or update snapshots. [camera-flash] +⚗️ Perform experiments. [alembic] +🔍️ Improve SEO. [mag] +🏷️ Add or update types. [label] +🌱 Add or update seed files. [seedling] +🚩 Add, update, or remove feature flags. [triangular-flag-on-post] +🥅 Catch errors. [goal-net] +💫 Add or update animations and transitions. [animation] +🗑️ Deprecate code that needs to be cleaned up. [wastebasket] +🛂 Work on code related to authorization, roles and permissions. [passport-control] +🩹 Simple fix for a non-critical issue. [adhesive-bandage] +🧐 Data exploration/inspection. [monocle-face] +⚰️ Remove dead code. [coffin] +# GITMOJI ENDS HERE + +# EMOJI STARTS HERE 😀 Grinning Face 😁 Beaming Face With Smiling Eyes 😂 Face With Tears of Joy @@ -121434,3 +121520,4 @@ z latin small letter z 鼖 cjk compatibility ideograph-2fa1b 鼻 cjk compatibility ideograph-2fa1c 𪘀 cjk compatibility ideograph-2fa1d +# EMOJI ENDS HERE |
