on master help sign in
Include syntaxes and themes in repository

This changes a few things: - All syntaxes and themes are now stored (as submodules) under assets/syntaxes and assets/themes - The default directories for syntaxes and themes are "syntaxes" and "themes" (used to be "syntax" and "themes") - The "bat cache" command can now take a `--source <dir>` and `--target <dir>` option. - The cached files have been renamed to "themes.bin" and "syntaxes.bin"

commit145b99f01c19416b5d6419d6bcf3d51a771a5518 authorsharkdp <davidpeter@web.de> dateWed 16 May 2018, 21:22 (8 years ago) parent9af1d2b
17 files changed+78−53
.gitmodules+18 README.md+2−2 assets/create.sh+6−32 assets/syntax_set assets/syntaxes.bin assets/syntaxes/Elixir+1 assets/syntaxes/Julia+1 assets/syntaxes/Markdown-Extended+1 assets/syntaxes/Packages+1 assets/syntaxes/TOML+1 assets/theme_set assets/themes.bin assets/themes/Default.tmTheme+1 assets/themes/sublime-monokai-extended+1 src/app.rs+19−2 src/assets.rs+20−15 src/main.rs+6−2
.gitmodulesnew file+18
@@ -0,0 +1,18 @@
1+[submodule "assets/syntaxes/Elixir"]
2+ path = assets/syntaxes/Elixir
3+ url = https://github.com/princemaple/elixir-sublime-syntax/
4+[submodule "assets/syntaxes/Packages"]
5+ path = assets/syntaxes/Packages
6+ url = https://github.com/sublimehq/Packages/
7+[submodule "assets/syntaxes/TOML"]
8+ path = assets/syntaxes/TOML
9+ url = https://github.com/sharkdp/sublime_toml_highlighting
10+[submodule "assets/syntaxes/Julia"]
11+ path = assets/syntaxes/Julia
12+ url = https://github.com/JuliaEditorSupport/Julia-sublime
13+[submodule "assets/themes/sublime-monokai-extended"]
14+ path = assets/themes/sublime-monokai-extended
15+ url = https://github.com/jonschlinkert/sublime-monokai-extended
16+[submodule "assets/syntaxes/Markdown-Extended"]
17+ path = assets/syntaxes/Markdown-Extended
18+ url = https://github.com/jonschlinkert/sublime-markdown-extended
README.md+2−2
@@ -136,8 +136,8 @@ ln -s "sublime-monokai-extended/Monokai Extended.tmTheme" Default.tmTheme
136136Create a folder with language definition files:
137137
138138``` bash
139−mkdir -p "$BAT_CONFIG_DIR/syntax"
140−cd "$BAT_CONFIG_DIR/syntax"
139+mkdir -p "$BAT_CONFIG_DIR/syntaxes"
140+cd "$BAT_CONFIG_DIR/syntaxes"
141141
142142# Download some language definition files, for example:
143143git clone https://github.com/sublimehq/Packages/
assets/create.sh+6−32
@@ -1,37 +1,11 @@
1−set -e
1+#!/bin/bash
22
3−THEME_FOLDER="$HOME/.config/bat/themes"
4−SYNTAX_FOLDER="$HOME/.config/bat/syntax"
3+ASSET_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
54
6−if [ ! -e "$THEME_FOLDER" ]; then
7− mkdir -p "$THEME_FOLDER"
8− (
9− cd "$THEME_FOLDER"
10− git clone https://github.com/jonschlinkert/sublime-monokai-extended
11− ln -s "sublime-monokai-extended/Monokai Extended.tmTheme" Default.tmTheme
12− )
13−fi
5+DEFAULT_MARKDOWN_SYNTAX="$ASSET_DIR/syntaxes/Packages/Markdown"
146
15−if [ ! -e "$SYNTAX_FOLDER" ]; then
16− mkdir -p "$SYNTAX_FOLDER"
17− (
18− cd "$SYNTAX_FOLDER"
19− git clone https://github.com/sublimehq/Packages/
7+rm -rf "$DEFAULT_MARKDOWN_SYNTAX"
208
21− # Patch JavaScript syntax
22− sed -i -e 's/{{identifier_break}}+/{{identifier_break}}/' Packages/JavaScript/JavaScript.sublime-syntax
9+bat cache --init --source="$ASSET_DIR" --target="$ASSET_DIR"
2310
24− # Use extended Markdown syntax
25− rm -rf Packages/Markdown
26− git clone https://github.com/jonschlinkert/sublime-markdown-extended
27−
28− # Add additional sxntax definitions
29− git clone https://github.com/princemaple/elixir-sublime-syntax/
30− git clone https://github.com/sharkdp/sublime_toml_highlighting
31− git clone https://github.com/JuliaEditorSupport/Julia-sublime
32− )
33−fi
34−
35−bat cache --init
36−
37−cp "$HOME/.cache/bat"/* .
11+git -C "$ASSET_DIR/syntaxes/Packages" checkout "$DEFAULT_MARKDOWN_SYNTAX"
assets/syntax_setdeleted

Binary file not shown.

assets/syntaxes.binnew file

Binary file not shown.

assets/syntaxes/Elixirnew file+1

Submodule changed.

assets/syntaxes/Julianew file+1

Submodule changed.

assets/syntaxes/Markdown-Extendednew file+1

Submodule changed.

assets/syntaxes/Packagesnew file+1

Submodule changed.

assets/syntaxes/TOMLnew file+1

Submodule changed.

assets/theme_setdeleted

Binary file not shown.

assets/themes.binnew file

Binary file not shown.

assets/themes/Default.tmThemenew file+1
@@ -0,0 +1 @@
1+sublime-monokai-extended/Monokai Extended.tmTheme
assets/themes/sublime-monokai-extendednew file+1

Submodule changed.

src/app.rs+19−2
@@ -117,7 +117,8 @@ impl App {
117117 Arg::with_name("init")
118118 .long("init")
119119 .short("i")
120− .help("Initialize the cache by loading from the config dir"),
120+ .help("Initialize the syntax/theme cache")
121+ .long_help("Initialize the syntax/theme cache by loading from the source directory (default: the configuration directory)"),
121122 )
122123 .arg(
123124 Arg::with_name("clear")
@@ -135,7 +136,23 @@ impl App {
135136 ArgGroup::with_name("cache-actions")
136137 .args(&["init", "clear", "config-dir"])
137138 .required(true),
138− ),
139+ )
140+ .arg(
141+ Arg::with_name("source")
142+ .long("source")
143+ .requires("init")
144+ .takes_value(true)
145+ .value_name("dir")
146+ .help("Use a different source for loading syntaxes and themes from"),
147+ )
148+ .arg(
149+ Arg::with_name("target")
150+ .long("target")
151+ .requires("init")
152+ .takes_value(true)
153+ .value_name("dir")
154+ .help("Use a different source to store the cached syntax and theme set"),
155+ )
139156 )
140157 .help_message("Print this help message.")
141158 .version_message("Show version information.")
src/assets.rs+20−15
@@ -3,7 +3,7 @@ use errors::*;
33use std::borrow::Cow;
44use std::fs::{self, File};
55use std::io;
6−use std::path::PathBuf;
6+use std::path::{Path, PathBuf};
77use syntect::dumps::{dump_to_file, from_binary, from_reader};
88use syntect::highlighting::{Theme, ThemeSet};
99use syntect::parsing::SyntaxSet;
@@ -22,11 +22,10 @@ impl HighlightingAssets {
2222 Self::from_cache().unwrap_or_else(|_| Self::from_binary())
2323 }
2424
25− pub fn from_files() -> Result<Self> {
26− let config_dir = PROJECT_DIRS.config_dir();
27−
28− let theme_dir = config_dir.join("themes");
25+ pub fn from_files(dir: Option<&Path>) -> Result<Self> {
26+ let source_dir = dir.unwrap_or_else(|| PROJECT_DIRS.config_dir());
2927
28+ let theme_dir = source_dir.join("themes");
3029 let theme_set = ThemeSet::load_from_folder(&theme_dir).map_err(|_| {
3130 io::Error::new(
3231 io::ErrorKind::Other,
@@ -38,7 +37,13 @@ impl HighlightingAssets {
3837 })?;
3938
4039 let mut syntax_set = SyntaxSet::new();
41− let syntax_dir = config_dir.join("syntax");
40+ let syntax_dir = source_dir.join("syntaxes");
41+ if !syntax_dir.exists() {
42+ return Err(format!(
43+ "Could not load syntaxes from '{}'",
44+ syntax_dir.to_string_lossy()
45+ ).into());
46+ }
4247 let _ = syntax_set.load_syntaxes(syntax_dir, true);
4348 syntax_set.load_plain_text_syntax();
4449
@@ -77,9 +82,9 @@ impl HighlightingAssets {
7782 }
7883
7984 fn from_binary() -> Self {
80− let mut syntax_set: SyntaxSet = from_binary(include_bytes!("../assets/syntax_set"));
85+ let mut syntax_set: SyntaxSet = from_binary(include_bytes!("../assets/syntaxes.bin"));
8186 syntax_set.link_syntaxes();
82− let theme_set: ThemeSet = from_binary(include_bytes!("../assets/theme_set"));
87+ let theme_set: ThemeSet = from_binary(include_bytes!("../assets/themes.bin"));
8388
8489 HighlightingAssets {
8590 syntax_set,
@@ -87,11 +92,11 @@ impl HighlightingAssets {
8792 }
8893 }
8994
90− pub fn save(&self) -> Result<()> {
91− let cache_dir = PROJECT_DIRS.cache_dir();
92− let _ = fs::create_dir(cache_dir);
93− let theme_set_path = theme_set_path();
94− let syntax_set_path = syntax_set_path();
95+ pub fn save(&self, dir: Option<&Path>) -> Result<()> {
96+ let target_dir = dir.unwrap_or_else(|| PROJECT_DIRS.cache_dir());
97+ let _ = fs::create_dir(target_dir);
98+ let theme_set_path = target_dir.join("themes.bin");
99+ let syntax_set_path = target_dir.join("syntaxes.bin");
95100
96101 print!(
97102 "Writing theme set to {} ... ",
@@ -137,11 +142,11 @@ impl HighlightingAssets {
137142}
138143
139144pub fn theme_set_path() -> PathBuf {
140− PROJECT_DIRS.cache_dir().join("theme_set")
145+ PROJECT_DIRS.cache_dir().join("themes.bin")
141146}
142147
143148pub fn syntax_set_path() -> PathBuf {
144− PROJECT_DIRS.cache_dir().join("syntax_set")
149+ PROJECT_DIRS.cache_dir().join("syntaxes.bin")
145150}
146151
147152pub fn config_dir() -> Cow<'static, str> {
src/main.rs+6−2
@@ -27,6 +27,7 @@ mod terminal;
2727
2828use std::fs::{self, File};
2929use std::io::{self, BufRead, BufReader, Write};
30+use std::path::Path;
3031use std::process::{self, Child, Command, Stdio};
3132
3233#[cfg(unix)]
@@ -206,8 +207,11 @@ fn run() -> Result<()> {
206207 match app.matches.subcommand() {
207208 ("cache", Some(cache_matches)) => {
208209 if cache_matches.is_present("init") {
209− let assets = HighlightingAssets::from_files()?;
210− assets.save()?;
210+ let source_dir = cache_matches.value_of("source").map(Path::new);
211+ let target_dir = cache_matches.value_of("target").map(Path::new);
212+
213+ let assets = HighlightingAssets::from_files(source_dir)?;
214+ assets.save(target_dir)?;
211215 } else if cache_matches.is_present("clear") {
212216 print!("Clearing theme set cache ... ");
213217 fs::remove_file(theme_set_path()).ok();