-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-worktree-switcher: init at 0.2.3
[`git worktree` documentation](https://git-scm.com/docs/git-worktree) [`git-worktree-switcher` repository](https://github.com/mateusauler/git-worktree-switcher) From the project's description: > Switch between git worktrees with speed. It's a wrapper script around `git worktree` making some tasks, like switching between worktrees, easier. > [!Note] > `git worktree` is a little known feature and adding QoL things can help it's adoption as it's a considerable upgrade against the `git stash` workflow.
- Loading branch information
Showing
3 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
pkgs/by-name/gi/git-worktree-switcher/add_list_option.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
diff --git a/wt b/wt | ||
index 9e18674..1aaf2b5 100755 | ||
--- a/wt | ||
+++ b/wt | ||
@@ -160,6 +160,9 @@ init() { | ||
} | ||
|
||
case "${args[0]}" in | ||
+list) | ||
+ worktree_list_names | ||
+ ;; | ||
names) | ||
worktree_list_names | ||
;; |
80 changes: 80 additions & 0 deletions
80
pkgs/by-name/gi/git-worktree-switcher/disable-update.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
diff --git a/wt b/wt | ||
index 9e18674..c8ee312 100755 | ||
--- a/wt | ||
+++ b/wt | ||
@@ -27,26 +27,12 @@ help_message() { | ||
echo -e "\twt: go to the main worktree" | ||
echo -e "\twt <worktree-name>: search for worktree names and change to that directory." | ||
echo -e "\twt names: list out only the git worktree names." | ||
- echo -e "\twt update: update to the latest release of worktree switcher." | ||
+ echo -e "\twt update: Check for updates to worktree switcher." | ||
echo -e "\twt version: show the CLI version." | ||
echo -e "\twt init <shell>: print the init script for <shell>." | ||
echo -e "\twt help: shows this help message." | ||
} | ||
|
||
-download_latest_update() { | ||
- download_url=$(curl -sL $RELEASE_API_URL | jq -r '.assets[0].browser_download_url') | ||
- | ||
- echo "Downloading latest version $fetched_tag_name" | ||
- curl -sL -o "$TMP_PATH" "$download_url" | ||
- | ||
- echo "Updating to latest version..." | ||
- chmod +x "$TMP_PATH" | ||
- sudo mv "$TMP_PATH" "$BINARY_PATH" | ||
- rm -f "$TMP_PATH" | ||
- | ||
- echo "You are using the latest version of worktree switcher: $fetched_tag_name" | ||
-} | ||
- | ||
check_release_version() { | ||
fetched_tag_name=$(check_and_cache_update) | ||
|
||
@@ -54,7 +40,8 @@ check_release_version() { | ||
echo "You have the latest version of worktree switcher!" | ||
echo "Version: $VERSION" | ||
else | ||
- download_latest_update | ||
+ echo "There is an update available." | ||
+ echo "Auto update functionality is disabled as git worktree switcher was installed using nix." | ||
fi | ||
} | ||
|
||
@@ -68,29 +55,6 @@ update() { | ||
fi | ||
} | ||
|
||
-auto_check_update() { | ||
- show_updates() { | ||
- if [[ "$1" != "$VERSION" ]]; then | ||
- echo "Version $1 available! Run 'wt update' to update." 1>&2 | ||
- echo "Currently running version $VERSION." 1>&2 | ||
- fi | ||
- } | ||
- | ||
- if [[ -f "$VERSION_CACHE_FILE" ]]; then | ||
- check_timestamp=$(jq -r '.timestamp' < "$VERSION_CACHE_FILE") | ||
- latest_known_version=$(jq -r '.version' < "$VERSION_CACHE_FILE") | ||
- one_day_ago_epoch=$(date -d '1 days ago' +%s) | ||
- | ||
- if (( check_timestamp > one_day_ago_epoch )); then | ||
- show_updates "$latest_known_version" | ||
- return 0 | ||
- fi | ||
- fi | ||
- | ||
- fetched_tag_name=$(check_and_cache_update) | ||
- show_updates "$fetched_tag_name" | ||
-} | ||
- | ||
check_and_cache_update() { | ||
echo "Checking for updates..." 1>&2 | ||
fetched_tag_name=$(curl -sL $RELEASE_API_URL | jq -r '.tag_name') | ||
@@ -176,7 +140,6 @@ init) | ||
init | ||
;; | ||
*) | ||
- auto_check_update | ||
directory=$(git worktree list --porcelain | sed -n '/'"${arg:-.}"'/{s/^worktree\s*//p;q}') | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
lib, | ||
stdenv, | ||
fetchFromGitHub, | ||
makeWrapper, | ||
installShellFiles, | ||
git, | ||
jq, | ||
}: | ||
|
||
stdenv.mkDerivation (finalAttrs: { | ||
pname = "git-worktree-switcher"; | ||
version = "0.2.3"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "mateusauler"; | ||
repo = "git-worktree-switcher"; | ||
rev = "refs/tags/${finalAttrs.version}-fork"; | ||
hash = "sha256-fjY+ieUI7m/4gb68/1a+90aIc9iMyQortVd7oHN4STw="; | ||
}; | ||
|
||
buildInputs = [ | ||
jq | ||
git | ||
]; | ||
|
||
nativeBuildInputs = [ | ||
makeWrapper | ||
installShellFiles | ||
]; | ||
|
||
patches = [ | ||
./disable-update.patch # Disable update and auto update functionality | ||
./add_list_option.patch # Add `list` option to be more intuitive (`git worktree list`) | ||
]; | ||
|
||
installPhase = '' | ||
mkdir -p $out/bin | ||
cp wt $out/bin | ||
wrapProgram $out/bin/wt --prefix PATH : ${ | ||
lib.makeBinPath [ | ||
git | ||
jq | ||
] | ||
} | ||
installShellCompletion --zsh completions/_wt_completion | ||
installShellCompletion --bash completions/wt_completion | ||
installShellCompletion --fish completions/wt.fish | ||
''; | ||
|
||
meta = { | ||
homepage = "https://github.com/mateusauler/git-worktree-switcher"; | ||
description = "Switch between git worktrees with speed."; | ||
license = lib.licenses.mit; | ||
platforms = lib.platforms.all; | ||
maintainers = with lib.maintainers; [ jiriks74 ]; | ||
}; | ||
}) |