From af79728ac310b327876900c05564e3df6abd452a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 17 Jun 2024 09:26:03 -0400 Subject: [PATCH] tab complete special remotes An oversight.. And with the work in progress proxy and cluster, there can be additional remotes that are not listed in .git/config, but are available. Making those more discoverable is another big benefit of this. --- CHANGELOG | 1 + CmdLine/GitAnnex/Options.hs | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e42f967b5b..6c5864aa3f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ git-annex (10.20240532) UNRELEASED; urgency=medium * Fix a bug where interrupting git-annex while it is updating the git-annex branch for an export could later lead to git fsck complaining about missing tree objects. + * Tab completion of options like --from now includes special remotes. * Fix Windows build with Win32 2.13.4+ Thanks, Oleg Tolmatcev diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index ed6bca99c7..80ed6c2575 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -40,6 +40,7 @@ import qualified Types.Backend as Backend import Utility.HumanTime import Utility.DataUnits import Annex.Concurrent +import Remote.List -- Options that are accepted by all git-annex sub-commands, -- although not always used. @@ -569,14 +570,30 @@ parseDaemonOptions canstop ) completeRemotes :: HasCompleter f => Mod f a -completeRemotes = completer $ mkCompleter $ \input -> do - r <- maybe (pure Nothing) (Just <$$> Git.Config.read) - =<< Git.Construct.fromCwd - return $ filter (input `isPrefixOf`) $ - mapMaybe remoteKeyToRemoteName $ - filter isRemoteUrlKey $ - maybe [] (M.keys . config) r - +completeRemotes = completer $ mkCompleter $ \input -> + Git.Construct.fromCwd >>= \case + Nothing -> return [] + Just g -> completeRemotes' g input + +completeRemotes' :: Repo -> [Char] -> IO [[Char]] +completeRemotes' g input = do + g' <- Git.Config.read g + state <- Annex.new g' + Annex.eval state $ do + Annex.setOutput QuietOutput + gc <- Annex.getGitConfig + if isinitialized gc + then do + rs <- remoteList + matches $ map Remote.name rs + else matches $ + mapMaybe remoteKeyToRemoteName $ + filter isRemoteUrlKey $ + M.keys $ config g + where + isinitialized gc = annexUUID gc /= NoUUID && isJust (annexVersion gc) + matches = return . filter (input `isPrefixOf`) + completeBackends :: HasCompleter f => Mod f a completeBackends = completeWith $ map (decodeBS . formatKeyVariety . Backend.backendVariety) Backend.builtinList