diff --git a/pkgs/by-name/gi/git-worktree-switcher/add_list_option.patch b/pkgs/by-name/gi/git-worktree-switcher/add_list_option.patch new file mode 100644 index 0000000000000..6241ba92b5348 --- /dev/null +++ b/pkgs/by-name/gi/git-worktree-switcher/add_list_option.patch @@ -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 + ;; diff --git a/pkgs/by-name/gi/git-worktree-switcher/disable-update.patch b/pkgs/by-name/gi/git-worktree-switcher/disable-update.patch new file mode 100644 index 0000000000000..d82e98db82d98 --- /dev/null +++ b/pkgs/by-name/gi/git-worktree-switcher/disable-update.patch @@ -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 : 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 : print the init script for ." + 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 diff --git a/pkgs/by-name/gi/git-worktree-switcher/package.nix b/pkgs/by-name/gi/git-worktree-switcher/package.nix new file mode 100644 index 0000000000000..4e638ac89cd8e --- /dev/null +++ b/pkgs/by-name/gi/git-worktree-switcher/package.nix @@ -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 ]; + }; +})