fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes Altmanninger__fish_complete_list: strip "--foo=" prefix from replacing completions320ebb685

master
3.4 KiB78 linesraw
1# ht Bob B@Clojurians Slack
2# https://raw.githubusercontent.com/bobisageek/bb-scripts/main/clj-alils.clj
3#
4# Babashka code for listing all aliases and tools available from the current context
5# based on :config-files from `clojure -Sdescribe`
6
7set -l bb_helper '
8(require \'[babashka.fs :as fs])
9
10(def config (->> (with-out-str (babashka.tasks/clojure "-Sdescribe"))
11                 clojure.edn/read-string))
12
13(defn configs []
14  (reverse (:config-files config)))
15
16(defn aliases-from-config [path]
17  (->> (clojure.edn/read-string (slurp path))
18       :aliases
19       keys
20       (map name)
21       sort))
22
23(defn installed-tools
24  []
25  (as-> config $
26    (:config-dir $)
27    (str $ "/tools/")
28    (fs/match $ "regex:.*\\\\.edn")
29    (map fs/file-name $)
30    (map #(fs/strip-ext % {:ext "edn"}) $)))
31
32(defn aliases []
33  (->> (configs)
34       (mapcat aliases-from-config)
35       dedupe))
36
37(run! println
38      (case (first *command-line-args*)
39        "tools" (installed-tools)
40        (aliases)))'
41
42function __fish_clj_aliases -V bb_helper
43    command -q bb; or return
44    bb -e "$bb_helper"
45end
46
47function __fish_clj_tools -V bb_helper
48    command -q bb; or return
49    bb -e "$bb_helper" tools
50end
51
52complete -c clj -s X -x -r -k -a "(__fish_stripprefix='^-\w*X' __fish_complete_list : __fish_clj_aliases)" -d "Use concatenated aliases to modify classpath or supply exec fn/args"
53complete -c clj -s A -x -r -k -a "(__fish_stripprefix='^-\w*A' __fish_complete_list : __fish_clj_aliases)" -d "Use concatenated aliases to modify classpath"
54complete -c clj -s M -x -r -k -a "(__fish_stripprefix='^-\w*M' __fish_complete_list : __fish_clj_aliases)" -d "Use concatenated aliases to modify classpath or supply main opts"
55complete -c clj -s T -x -r -k -a "(__fish_stripprefix='^-\w*T' __fish_complete_list : __fish_clj_tools)" -d "Invoke tool by name or via aliases ala -X"
56
57complete -c clj -f -o Sdeps -r -d "Deps data to use as the last deps file to be merged"
58complete -c clj -f -o Spath -d "Compute classpath and echo to stdout only"
59complete -c clj -f -o Spom -d "Generate (or update) pom.xml with deps and paths"
60complete -c clj -f -o Stree -d "Print dependency tree"
61complete -c clj -f -o Scp -r -d "Do NOT compute or cache classpath, use this one instead"
62complete -c clj -f -o Srepro -d "Ignore the ~/.clojure/deps.edn config file"
63complete -c clj -f -o Sforce -d "Force recomputation of the classpath (don't use the cache)"
64complete -c clj -f -o Sverbose -d "Print important path info to console"
65complete -c clj -f -o Sdescribe -d "Print environment and command parsing info as data"
66complete -c clj -f -o Sthreads -d "Set specific number of download threads"
67complete -c clj -f -o Strace -d "Write a trace.edn file that traces deps expansion"
68
69complete -c clj -k -f -s h -l help -d "Show help"
70complete -c clj -f -s P -d "Prepare deps - download libs, cache classpath, but don't exec"
71complete -c clj -s J -d "Pass opt through in java_opts, ex: -J-Xmx512m"
72complete -c clj -s i -l init -r -d "Load a file or resource"
73complete -c clj -f -s e -l eval -r -d "Eval exprs in string; print non-nil values"
74complete -c clj -f -l report -d "Report uncaught exception to \"file\" (default), \"stderr\", or \"none\""
75complete -c clj -f -o version -l version -d "Print the version to stdout and exit"
76complete -c clj -f -s m -l main -d "Call the -main function from namespace w/args"
77complete -c clj -f -s r -l repl -d "Run a repl"
78complete -c clj -r -d "Run a script from a file or resource"