(use sh) (defn prompt [] (def repo-root ($<_ jj root --ignore-working-copy)) (def template `change_id.shortest(8).prefix() ++ "#," ++ change_id.shortest(8).rest() ++ "#," ++ commit_id.shortest(8).prefix() ++ "#," ++ commit_id.shortest(8).rest() ++ "#," ++ divergent ++ "#," ++ description ++ "#," ++ bookmarks.join(",")`) # (def template "change_id.shortest(8).prefix()") (def stdout ($< jj log -r @ -T ,template --no-graph --no-pager --color never --ignore-working-copy -R ,repo-root)) (def [change-id-prefix change-id-suffix commit-id-prefix commit-id-suffix divergent description branches] (string/split "#," stdout)) {:change-id [change-id-prefix change-id-suffix] :commit-id [commit-id-prefix commit-id-suffix] :divergent (= divergent "true") :description description :branches branches}) (def color-reset "%f") (def color-blue "%F{blue}") (def color-pink "%F{magenta}") (def color-dark "%F{8}") (defn render [parsed] (string " [" color-pink ((parsed :change-id) 0) color-dark ((parsed :change-id) 1) color-reset " " color-blue ((parsed :commit-id) 0) color-dark ((parsed :commit-id) 1) color-reset (if-not (empty? (parsed :branches)) (string " on " (parsed :branches))) "]")) (defn main [&] (def [ok jj] (protect (prompt))) (if ok (prin (render jj))))