优化信息

This commit is contained in:
2026-02-04 17:07:04 +08:00
parent 40387909d3
commit 16ff180188
11 changed files with 48 additions and 48 deletions

3
.gitignore vendored
View File

@@ -1 +1,2 @@
dist-newstyle dist-newstyle
cache

View File

@@ -13,9 +13,10 @@
- **静默模式** - 抑制输出消息,适合脚本使用 - **静默模式** - 抑制输出消息,适合脚本使用
- **跨平台支持** - 支持 Windows、macOS 和 Linux - **跨平台支持** - 支持 Windows、macOS 和 Linux
## 版本 ## 源码
当前版本: **0.3.0.1** - [Github](https://github.com/sidneylyzhang/quickjump)
- [Gitea](https://git.lyz.one/sidneyzhang/quickjump)
## 安装 ## 安装

View File

@@ -8,20 +8,17 @@ module Commands
, printShellIntegration , printShellIntegration
) where ) where
import Control.Monad (forM_, unless, when) import Control.Monad (forM_, unless)
import Data.List (intercalate) import Data.List (intercalate)
import Data.Map (Map)
import qualified Data.Map as M import qualified Data.Map as M
import Data.Maybe (fromMaybe, isJust) import Data.Maybe (fromMaybe)
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as T import qualified Data.Text as T
import System.Directory (doesDirectoryExist, doesFileExist) import System.Directory (doesDirectoryExist)
import System.Environment (lookupEnv) import System.Exit (exitFailure)
import System.Exit (exitFailure, exitSuccess)
import System.FilePath ((</>))
import System.Info (os) import System.Info (os)
import System.IO (hFlush, stdout) import System.IO (hFlush, stdout)
import System.Process (callCommand, spawnCommand, waitForProcess) import System.Process (spawnCommand, waitForProcess)
import Config import Config
import Types import Types
@@ -135,18 +132,18 @@ openPath p cfg quiet = do
-- 尝试使用配置的文件管理器,或者自动检测 -- 尝试使用配置的文件管理器,或者自动检测
let fm = fileManager cfg let fm = fileManager cfg
case fm of case fm of
Just cmd -> runFileManager cmd expanded quiet Just cmd -> runFileManager cmd expanded
Nothing -> autoDetectAndOpen expanded quiet Nothing -> autoDetectAndOpen expanded quiet
-- | 自动检测并打开文件管理器 -- | 自动检测并打开文件管理器
autoDetectAndOpen :: FilePath -> Bool -> IO () autoDetectAndOpen :: FilePath -> Bool -> IO ()
autoDetectAndOpen path quiet = do autoDetectAndOpen targetPath quiet = do
let (cmd, args) = case os of let (cmd, args) = case os of
"darwin" -> ("open", [path]) "darwin" -> ("open", [targetPath])
"mingw32" -> ("explorer", [path]) "mingw32" -> ("explorer", [targetPath])
"mingw64" -> ("explorer", [path]) "mingw64" -> ("explorer", [targetPath])
"cygwin" -> ("cygstart", [path]) "cygwin" -> ("cygstart", [targetPath])
_ -> ("xdg-open", [path]) -- Linux and others _ -> ("xdg-open", [targetPath]) -- Linux and others
-- 检查命令是否存在 -- 检查命令是否存在
exists <- commandExists cmd exists <- commandExists cmd
@@ -159,12 +156,12 @@ autoDetectAndOpen path quiet = do
putStrLn $ "Cannot open file manager. Please configure one:" putStrLn $ "Cannot open file manager. Please configure one:"
putStrLn $ " quickjump config set-file-manager <command>" putStrLn $ " quickjump config set-file-manager <command>"
-- 输出 cd 命令作为备选 -- 输出 cd 命令作为备选
putStrLn $ "cd " ++ show path putStrLn $ "cd " ++ show targetPath
-- | 运行文件管理器 -- | 运行文件管理器
runFileManager :: FilePath -> FilePath -> Bool -> IO () runFileManager :: FilePath -> FilePath -> IO ()
runFileManager cmd path quiet = do runFileManager cmd targetPath = do
expanded <- expandPath path expanded <- expandPath targetPath
let fullCmd = cmd ++ " " ++ show expanded let fullCmd = cmd ++ " " ++ show expanded
_ <- spawnCommand fullCmd >>= waitForProcess _ <- spawnCommand fullCmd >>= waitForProcess
return () return ()
@@ -174,19 +171,19 @@ runConfigCmd :: ConfigAction -> Bool -> IO ()
runConfigCmd action quiet = do runConfigCmd action quiet = do
cfg <- ensureConfigExists cfg <- ensureConfigExists
case action of case action of
ConfigAdd name path mDesc -> do ConfigAdd name targetPath mDesc -> do
expanded <- expandPath path expanded <- expandPath targetPath
exists <- doesDirectoryExist expanded exists <- doesDirectoryExist expanded
unless exists $ do unless exists $ do
unless quiet $ putStrLn $ "Warning: Directory does not exist: " ++ expanded unless quiet $ putStrLn $ "Warning: Directory does not exist: " ++ expanded
let entry = JumpEntry let entry = JumpEntry
{ path = path { path = targetPath
, description = mDesc , description = mDesc
, priority = 100 , priority = 100
} }
newCfg = cfg { entries = M.insert name entry (entries cfg) } newCfg = cfg { entries = M.insert name entry (entries cfg) }
saveConfig newCfg saveConfig newCfg
unless quiet $ putStrLn $ "Added '" ++ T.unpack name ++ "' -> " ++ path unless quiet $ putStrLn $ "Added '" ++ T.unpack name ++ "' -> " ++ targetPath
ConfigRemove name -> do ConfigRemove name -> do
if M.member name (entries cfg) if M.member name (entries cfg)
@@ -212,14 +209,14 @@ runConfigCmd action quiet = do
++ " -> " ++ padRight 30 (path entry) ++ " -> " ++ padRight 30 (path entry)
++ if T.null desc then "" else " # " ++ T.unpack desc ++ if T.null desc then "" else " # " ++ T.unpack desc
ConfigSetDefault path -> do ConfigSetDefault targetPath -> do
expanded <- expandPath path expanded <- expandPath targetPath
exists <- doesDirectoryExist expanded exists <- doesDirectoryExist expanded
unless exists $ do unless exists $ do
unless quiet $ putStrLn $ "Warning: Directory does not exist: " ++ expanded unless quiet $ putStrLn $ "Warning: Directory does not exist: " ++ expanded
let newCfg = cfg { defaultPath = Just path } let newCfg = cfg { defaultPath = Just targetPath }
saveConfig newCfg saveConfig newCfg
unless quiet $ putStrLn $ "Set default path to: " ++ path unless quiet $ putStrLn $ "Set default path to: " ++ targetPath
ConfigSetEditor cmd -> do ConfigSetEditor cmd -> do
let newCfg = cfg { editor = Just cmd } let newCfg = cfg { editor = Just cmd }
@@ -231,12 +228,12 @@ runConfigCmd action quiet = do
saveConfig newCfg saveConfig newCfg
unless quiet $ putStrLn $ "Set file manager to: " ++ cmd unless quiet $ putStrLn $ "Set file manager to: " ++ cmd
ConfigExport path -> do ConfigExport targetPath -> do
saveConfigTo path cfg saveConfigTo targetPath cfg
unless quiet $ putStrLn $ "Config exported to: " ++ path unless quiet $ putStrLn $ "Config exported to: " ++ targetPath
ConfigImport path merge -> do ConfigImport targetPath merge -> do
imported <- loadConfigFrom path imported <- loadConfigFrom targetPath
let merged = mergeConfigs cfg imported merge let merged = mergeConfigs cfg imported merge
saveConfig merged saveConfig merged
unless quiet $ unless quiet $

View File

@@ -34,7 +34,7 @@ getConfigPath = do
-- 首先检查环境变量 -- 首先检查环境变量
mEnvPath <- lookupEnv "QUICKJUMP_CONFIG" mEnvPath <- lookupEnv "QUICKJUMP_CONFIG"
case mEnvPath of case mEnvPath of
Just path -> return path Just configPath -> return configPath
Nothing -> do Nothing -> do
-- 默认使用 XDG 配置目录 -- 默认使用 XDG 配置目录
xdgConfig <- lookupEnv "XDG_CONFIG_HOME" xdgConfig <- lookupEnv "XDG_CONFIG_HOME"
@@ -47,19 +47,19 @@ getConfigPath = do
-- | 展开路径中的 ~ 和环境变量 -- | 展开路径中的 ~ 和环境变量
expandPath :: FilePath -> IO FilePath expandPath :: FilePath -> IO FilePath
expandPath path = do expandPath inputPath = do
-- 首先处理 ~ 展开 -- 首先处理 ~ 展开
expanded1 <- if take 1 path == "~" expanded1 <- if take 1 inputPath == "~"
then do then do
home <- getHomeDirectory home <- getHomeDirectory
return $ home </> drop 2 path return $ home </> drop 2 inputPath
else return path else return inputPath
-- 然后处理环境变量(支持 Unix $VAR 和 Windows %VAR% 格式) -- 然后处理环境变量(支持 Unix $VAR 和 Windows %VAR% 格式)
expandEnvVars expanded1 expandEnvVars expanded1
-- | 展开环境变量 -- | 展开环境变量
expandEnvVars :: FilePath -> IO FilePath expandEnvVars :: FilePath -> IO FilePath
expandEnvVars path = do expandEnvVars inputPath = do
-- 处理 Unix 风格的环境变量 $VAR -- 处理 Unix 风格的环境变量 $VAR
let expandUnixVars s = case s of let expandUnixVars s = case s of
'$':'{':rest -> '$':'{':rest ->
@@ -92,9 +92,9 @@ expandEnvVars path = do
c:cs -> (c:) <$> expandEnvVars cs c:cs -> (c:) <$> expandEnvVars cs
[] -> return [] [] -> return []
-- 根据操作系统选择展开方式 -- 根据操作系统选择展开方式
if '%' `elem` path if '%' `elem` inputPath
then expandWindowsVars path then expandWindowsVars inputPath
else expandUnixVars path else expandUnixVars inputPath
where where
isAlphaNum c = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') isAlphaNum c = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')
@@ -119,8 +119,8 @@ loadConfig = do
-- | 从指定路径加载配置 -- | 从指定路径加载配置
loadConfigFrom :: FilePath -> IO Config loadConfigFrom :: FilePath -> IO Config
loadConfigFrom path = do loadConfigFrom configPath = do
expanded <- expandPath path expanded <- expandPath configPath
result <- catch result <- catch
(Right <$> BL.readFile expanded) (Right <$> BL.readFile expanded)
(\e -> if isDoesNotExistError e (\e -> if isDoesNotExistError e
@@ -141,8 +141,8 @@ saveConfig cfg = do
-- | 保存配置到指定路径 -- | 保存配置到指定路径
saveConfigTo :: FilePath -> Config -> IO () saveConfigTo :: FilePath -> Config -> IO ()
saveConfigTo path cfg = do saveConfigTo configPath cfg = do
expanded <- expandPath path expanded <- expandPath configPath
createDirectoryIfMissing True (takeDirectory expanded) createDirectoryIfMissing True (takeDirectory expanded)
BL.writeFile expanded (encodePretty cfg) BL.writeFile expanded (encodePretty cfg)

BIN
cache/compiler vendored Normal file

Binary file not shown.

BIN
cache/config vendored Normal file

Binary file not shown.

BIN
cache/elaborated-plan vendored Normal file

Binary file not shown.

BIN
cache/improved-plan vendored Normal file

Binary file not shown.

1
cache/plan.json vendored Normal file

File diff suppressed because one or more lines are too long

BIN
cache/solver-plan vendored Normal file

Binary file not shown.

BIN
cache/source-hashes vendored Normal file

Binary file not shown.