Skip to content

Commit 2b44f58

Browse files
ss-oCopilot
andauthored
[fix]: opts, update repository files (#32)
* Enhance zsh-diff-so-fancy plugin with improved diff output and customization options - [fix [bug]: Zsh warnings when loading from Oh-my-zsh #30 Signed-off-by: Salvydas Lukosius <[email protected]> * Update .gitignore and trunk.yaml for improved plugin management and linting tools Signed-off-by: Salvydas Lukosius <[email protected]> * Add GitHub Copilot setup workflow for zsh-diff-so-fancy plugin Signed-off-by: Salvydas Lukosius <[email protected]> * Update zsh-diff-so-fancy.plugin.zsh Co-authored-by: Copilot <[email protected]> Signed-off-by: Sall <[email protected]> --------- Signed-off-by: Salvydas Lukosius <[email protected]> Signed-off-by: Sall <[email protected]> Co-authored-by: Salvydas Lukosius <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 49c4e4f commit 2b44f58

File tree

7 files changed

+114
-14
lines changed

7 files changed

+114
-14
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: GitHub Copilot Coding Agent Setup Guide
2+
3+
# This file is used by GitHub Copilot Coding Agent to set up the environment
4+
# See: https://docs.github.com/en/enterprise-cloud@latest/copilot/how-tos/agents/copilot-coding-agent/customizing-the-development-environment-for-copilot-coding-agent
5+
6+
on:
7+
# This workflow is intended to be used by GitHub Copilot
8+
workflow_dispatch:
9+
10+
# Explicitly define minimum required permissions
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
setup-guide:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Setup Prerequisites
19+
run: |
20+
echo "::setup::Install ZSH"
21+
sudo apt-get update
22+
sudo apt-get install -y zsh
23+
24+
- name: Setup diff-so-fancy
25+
run: |
26+
echo "::setup::Install diff-so-fancy"
27+
git clone https://github.com/so-fancy/diff-so-fancy.git /tmp/diff-so-fancy
28+
sudo cp /tmp/diff-so-fancy/diff-so-fancy /usr/local/bin/
29+
sudo chmod +x /usr/local/bin/diff-so-fancy
30+
31+
- name: Test Environment
32+
run: |
33+
echo "::test::Test diff-so-fancy installation"
34+
diff-so-fancy --version
35+
36+
- name: Setup Instructions
37+
run: |
38+
echo "::info::Plugin Usage"
39+
echo "This zsh plugin provides:"
40+
echo "- git dsf: A Git subcommand to run Git diffs through diff-so-fancy"
41+
echo "- fancy-diff: A helper to compare two files with diff-so-fancy"
42+
43+
echo "::info::Environment Variables"
44+
echo "You can customize the output by setting these environment variables:"
45+
echo "- FANCY_DIFF_LESS_OPTS: Options for less when using fancy-diff"
46+
echo "- GIT_DSF_LESS_OPTS: Options for less when using git dsf"
47+
48+
echo "::info::Testing the plugin"
49+
echo "To test the plugin after changes:"
50+
echo "1. Run 'zsh' to start a new zsh session"
51+
echo "2. Source the plugin: source zsh-diff-so-fancy.plugin.zsh"
52+
echo "3. Create two test files with different content"
53+
echo "4. Run: fancy-diff file1 file2"
54+
echo "5. Run: git dsf (in a git repository)"
55+
56+
- name: Development Workflow
57+
run: |
58+
echo "::info::Development Workflow"
59+
echo "1. Make changes to zsh-diff-so-fancy.plugin.zsh or scripts in bin/"
60+
echo "2. Ensure scripts have proper error handling and comments"
61+
echo "3. Test changes in a zsh shell"
62+
echo "4. Update documentation in docs/README.md if needed"
63+
echo "5. Run trunk check before committing: trunk check"

.trunk/.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
*logs
33
*actions
44
*notifications
5-
tools
6-
tools.log
5+
*tools
76
plugins
87
user_trunk.yaml
98
user.yaml

.trunk/trunk.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ cli:
44
plugins:
55
sources:
66
- id: trunk
7-
ref: v1.7.0
7+
ref: v1.7.1
88
uri: https://github.com/trunk-io/plugins
99
lint:
1010
enabled:
11-
12-
- trufflehog@3.88.35
11+
12+
- trufflehog@3.90.0
1313
1414
1515
16-
- gitleaks@8.26.0
16+
- gitleaks@8.27.2
1717
1818
1919
- git-diff-check
20-
- prettier@3.5.3
20+
- prettier@3.6.2
2121
runtimes:
2222
enabled:
2323

bin/fancy-diff

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ ff() {
2222
# Use FANCY_DIFF_LESS_OPTS if set, otherwise fallback to a default.
2323
# The plugin typically sets a default for FANCY_DIFF_LESS_OPTS.
2424
local less_opts="${FANCY_DIFF_LESS_OPTS:---tabs=4 -FRXSi}"
25+
26+
# Run diff with unified output (-u), colorized, and pipe through diff-so-fancy
27+
# The --patch flag preserves the original diff format in the output
28+
# This is useful for interoperability with tools that parse diff output
2529
command diff -u "$1" "$2" --color=always | diff-so-fancy --patch | less "${less_opts}"
2630
}
2731

bin/git-dsf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ f() {
66
# The plugin zsh-diff-so-fancy.plugin.zsh typically sets a default for GIT_DSF_LESS_OPTS.
77
local less_opts="${GIT_DSF_LESS_OPTS:---tabs=4 -FRXSi}"
88

9+
# Handle Git prefix directory if set (for submodules and special Git contexts)
910
[[ -z "${GIT_PREFIX}" ]] || builtin cd -q "${GIT_PREFIX}" && \
11+
# Run git diff with color, pipe through diff-so-fancy
12+
# The --patch flag preserves the original diff format in the output
13+
# This is useful for interoperability with tools that parse git diff output
1014
command git diff --color=always "$@" | diff-so-fancy --patch | less "${less_opts}"
1115
}
1216

docs/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ A simple plugin integrating [so-fancy/diff-so-fancy](https://github.com/so-fancy
2828
- `git dsf <files>` to see a diff rendered by diff-so-fancy
2929
- `fancy-diff <file1> <file2>` to compare two files with diff-so-fancy
3030

31+
## Customization
32+
33+
You can customize the `less` options by setting these environment variables in your `.zshrc` before loading the plugin:
34+
35+
```shell
36+
# Customize less options for fancy-diff
37+
export FANCY_DIFF_LESS_OPTS="--tabs=2 -RFX"
38+
39+
# Customize less options for git dsf
40+
export GIT_DSF_LESS_OPTS="--tabs=2 -FRXS"
41+
```
42+
43+
The default is `--tabs=4 -FRXSi` for both commands if not specified.
44+
3145
## Manual Configuration
3246

3347
```shell
@@ -59,6 +73,12 @@ git config --global interactive.diffFilter "diff-so-fancy --patch"
5973
- **rulerWidth** (int, default: full width)
6074
Set a fixed width for the file header separator.
6175

76+
### Plugin Details
77+
78+
- Both `fancy-diff` and `git-dsf` use the `--patch` flag with `diff-so-fancy` to preserve the original diff format in the output, which is useful for interoperability with tools that parse diff output.
79+
- The plugin follows the [Zsh Plugin Standard](https://wiki.zshell.dev/community/zsh_plugin_standard) and provides an unload function for plugin managers that support unloading.
80+
- The plugin checks if `diff-so-fancy` is installed and provides a helpful warning if it's not found.
81+
6282
### Installation with [Zi](https://github.com/z-shell/zi)
6383

6484
```shell

zsh-diff-so-fancy.plugin.zsh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ if ! command -v diff-so-fancy >/dev/null 2>&1; then
1919
return 1
2020
fi
2121

22-
# Default options for `less` used by `fancy-diff`.
23-
# Users can override this by setting FANCY_DIFF_LESS_OPTS in their zshrc.
24-
: "${FANCY_DIFF_LESS_OPTS:=--tabs=4 -FRXSi}"
22+
# Create the variables in the correct scope using typeset
23+
# This prevents them from leaking into the global namespace
24+
# Reference: https://github.com/z-shell/zsh-diff-so-fancy/issues/30
25+
() {
26+
# Default options for `less` used by `fancy-diff`.
27+
# Users can override this by setting FANCY_DIFF_LESS_OPTS in their zshrc.
28+
typeset -g FANCY_DIFF_LESS_OPTS="${FANCY_DIFF_LESS_OPTS:---tabs=4 -FRXSi}"
2529

26-
# Default options for `less` used by `git-dsf`.
27-
# Users can override this by setting GIT_DSF_LESS_OPTS in their zshrc.
28-
: "${GIT_DSF_LESS_OPTS:=--tabs=4 -FRXSi}"
30+
# Default options for `less` used by `git-dsf`.
31+
# Users can override this by setting GIT_DSF_LESS_OPTS in their zshrc.
32+
typeset -g GIT_DSF_LESS_OPTS="${GIT_DSF_LESS_OPTS:---tabs=4 -FRXSi}"
33+
}
2934

3035
# https://wiki.zshell.dev/community/zsh_plugin_standard#binaries-directory
3136
if [[ $PMSPEC != *b* ]] {
@@ -39,6 +44,11 @@ zsh_diff_so_fancy_plugin_unload() {
3944
# This reconstructs the path based on $0, relying on its initial normalization.
4045
path=( "${(@)path:#${0:h}/bin}" )
4146
fi
47+
48+
# Unset the global variables if they were set by this plugin
49+
# Note: We avoid unsetting if they might have been set by the user
50+
unset FANCY_DIFF_LESS_OPTS GIT_DSF_LESS_OPTS 2>/dev/null
51+
52+
# Clean up the function itself
4253
unfunction zsh_diff_so_fancy_plugin_unload
43-
# Add any other cleanup needed, like unsetting global variables or options set by the plugin.
4454
}

0 commit comments

Comments
 (0)