mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-03 04:08:50 +01:00
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"
This commit is contained in:
parent
9af1d2b891
commit
145b99f01c
18
.gitmodules
vendored
Normal file
18
.gitmodules
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
[submodule "assets/syntaxes/Elixir"]
|
||||||
|
path = assets/syntaxes/Elixir
|
||||||
|
url = https://github.com/princemaple/elixir-sublime-syntax/
|
||||||
|
[submodule "assets/syntaxes/Packages"]
|
||||||
|
path = assets/syntaxes/Packages
|
||||||
|
url = https://github.com/sublimehq/Packages/
|
||||||
|
[submodule "assets/syntaxes/TOML"]
|
||||||
|
path = assets/syntaxes/TOML
|
||||||
|
url = https://github.com/sharkdp/sublime_toml_highlighting
|
||||||
|
[submodule "assets/syntaxes/Julia"]
|
||||||
|
path = assets/syntaxes/Julia
|
||||||
|
url = https://github.com/JuliaEditorSupport/Julia-sublime
|
||||||
|
[submodule "assets/themes/sublime-monokai-extended"]
|
||||||
|
path = assets/themes/sublime-monokai-extended
|
||||||
|
url = https://github.com/jonschlinkert/sublime-monokai-extended
|
||||||
|
[submodule "assets/syntaxes/Markdown-Extended"]
|
||||||
|
path = assets/syntaxes/Markdown-Extended
|
||||||
|
url = https://github.com/jonschlinkert/sublime-markdown-extended
|
@ -136,8 +136,8 @@ ln -s "sublime-monokai-extended/Monokai Extended.tmTheme" Default.tmTheme
|
|||||||
Create a folder with language definition files:
|
Create a folder with language definition files:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
mkdir -p "$BAT_CONFIG_DIR/syntax"
|
mkdir -p "$BAT_CONFIG_DIR/syntaxes"
|
||||||
cd "$BAT_CONFIG_DIR/syntax"
|
cd "$BAT_CONFIG_DIR/syntaxes"
|
||||||
|
|
||||||
# Download some language definition files, for example:
|
# Download some language definition files, for example:
|
||||||
git clone https://github.com/sublimehq/Packages/
|
git clone https://github.com/sublimehq/Packages/
|
||||||
|
@ -1,37 +1,11 @@
|
|||||||
set -e
|
#!/bin/bash
|
||||||
|
|
||||||
THEME_FOLDER="$HOME/.config/bat/themes"
|
ASSET_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
SYNTAX_FOLDER="$HOME/.config/bat/syntax"
|
|
||||||
|
|
||||||
if [ ! -e "$THEME_FOLDER" ]; then
|
DEFAULT_MARKDOWN_SYNTAX="$ASSET_DIR/syntaxes/Packages/Markdown"
|
||||||
mkdir -p "$THEME_FOLDER"
|
|
||||||
(
|
|
||||||
cd "$THEME_FOLDER"
|
|
||||||
git clone https://github.com/jonschlinkert/sublime-monokai-extended
|
|
||||||
ln -s "sublime-monokai-extended/Monokai Extended.tmTheme" Default.tmTheme
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -e "$SYNTAX_FOLDER" ]; then
|
rm -rf "$DEFAULT_MARKDOWN_SYNTAX"
|
||||||
mkdir -p "$SYNTAX_FOLDER"
|
|
||||||
(
|
|
||||||
cd "$SYNTAX_FOLDER"
|
|
||||||
git clone https://github.com/sublimehq/Packages/
|
|
||||||
|
|
||||||
# Patch JavaScript syntax
|
bat cache --init --source="$ASSET_DIR" --target="$ASSET_DIR"
|
||||||
sed -i -e 's/{{identifier_break}}+/{{identifier_break}}/' Packages/JavaScript/JavaScript.sublime-syntax
|
|
||||||
|
|
||||||
# Use extended Markdown syntax
|
git -C "$ASSET_DIR/syntaxes/Packages" checkout "$DEFAULT_MARKDOWN_SYNTAX"
|
||||||
rm -rf Packages/Markdown
|
|
||||||
git clone https://github.com/jonschlinkert/sublime-markdown-extended
|
|
||||||
|
|
||||||
# Add additional sxntax definitions
|
|
||||||
git clone https://github.com/princemaple/elixir-sublime-syntax/
|
|
||||||
git clone https://github.com/sharkdp/sublime_toml_highlighting
|
|
||||||
git clone https://github.com/JuliaEditorSupport/Julia-sublime
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
|
|
||||||
bat cache --init
|
|
||||||
|
|
||||||
cp "$HOME/.cache/bat"/* .
|
|
||||||
|
Binary file not shown.
BIN
assets/syntaxes.bin
Normal file
BIN
assets/syntaxes.bin
Normal file
Binary file not shown.
1
assets/syntaxes/Elixir
Submodule
1
assets/syntaxes/Elixir
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 044d9af8a1cc5c4da234e60f4a22ce8603b2d772
|
1
assets/syntaxes/Julia
Submodule
1
assets/syntaxes/Julia
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 581805e47c7af5ab0a880aaef5b27f8c1ccc29aa
|
1
assets/syntaxes/Markdown-Extended
Submodule
1
assets/syntaxes/Markdown-Extended
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 7b7a83aeeaf3afc752f7d921b10051330557aa0e
|
1
assets/syntaxes/Packages
Submodule
1
assets/syntaxes/Packages
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 1cb4c3ec368c751d6f7ecfa16fe02ceff23a1f6b
|
1
assets/syntaxes/TOML
Submodule
1
assets/syntaxes/TOML
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit b5e3064e9950dd36a2debed2ea95ab90712ab06a
|
BIN
assets/theme_set
BIN
assets/theme_set
Binary file not shown.
BIN
assets/themes.bin
Normal file
BIN
assets/themes.bin
Normal file
Binary file not shown.
1
assets/themes/Default.tmTheme
Symbolic link
1
assets/themes/Default.tmTheme
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
sublime-monokai-extended/Monokai Extended.tmTheme
|
1
assets/themes/sublime-monokai-extended
Submodule
1
assets/themes/sublime-monokai-extended
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 1658f51c15400978b3f6ba7cf5ed6b171e71058c
|
21
src/app.rs
21
src/app.rs
@ -117,7 +117,8 @@ impl App {
|
|||||||
Arg::with_name("init")
|
Arg::with_name("init")
|
||||||
.long("init")
|
.long("init")
|
||||||
.short("i")
|
.short("i")
|
||||||
.help("Initialize the cache by loading from the config dir"),
|
.help("Initialize the syntax/theme cache")
|
||||||
|
.long_help("Initialize the syntax/theme cache by loading from the source directory (default: the configuration directory)"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("clear")
|
Arg::with_name("clear")
|
||||||
@ -135,7 +136,23 @@ impl App {
|
|||||||
ArgGroup::with_name("cache-actions")
|
ArgGroup::with_name("cache-actions")
|
||||||
.args(&["init", "clear", "config-dir"])
|
.args(&["init", "clear", "config-dir"])
|
||||||
.required(true),
|
.required(true),
|
||||||
),
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("source")
|
||||||
|
.long("source")
|
||||||
|
.requires("init")
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("dir")
|
||||||
|
.help("Use a different source for loading syntaxes and themes from"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("target")
|
||||||
|
.long("target")
|
||||||
|
.requires("init")
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("dir")
|
||||||
|
.help("Use a different source to store the cached syntax and theme set"),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
.help_message("Print this help message.")
|
.help_message("Print this help message.")
|
||||||
.version_message("Show version information.")
|
.version_message("Show version information.")
|
||||||
|
@ -3,7 +3,7 @@ use errors::*;
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use syntect::dumps::{dump_to_file, from_binary, from_reader};
|
use syntect::dumps::{dump_to_file, from_binary, from_reader};
|
||||||
use syntect::highlighting::{Theme, ThemeSet};
|
use syntect::highlighting::{Theme, ThemeSet};
|
||||||
use syntect::parsing::SyntaxSet;
|
use syntect::parsing::SyntaxSet;
|
||||||
@ -22,11 +22,10 @@ impl HighlightingAssets {
|
|||||||
Self::from_cache().unwrap_or_else(|_| Self::from_binary())
|
Self::from_cache().unwrap_or_else(|_| Self::from_binary())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_files() -> Result<Self> {
|
pub fn from_files(dir: Option<&Path>) -> Result<Self> {
|
||||||
let config_dir = PROJECT_DIRS.config_dir();
|
let source_dir = dir.unwrap_or_else(|| PROJECT_DIRS.config_dir());
|
||||||
|
|
||||||
let theme_dir = config_dir.join("themes");
|
|
||||||
|
|
||||||
|
let theme_dir = source_dir.join("themes");
|
||||||
let theme_set = ThemeSet::load_from_folder(&theme_dir).map_err(|_| {
|
let theme_set = ThemeSet::load_from_folder(&theme_dir).map_err(|_| {
|
||||||
io::Error::new(
|
io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
@ -38,7 +37,13 @@ impl HighlightingAssets {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut syntax_set = SyntaxSet::new();
|
let mut syntax_set = SyntaxSet::new();
|
||||||
let syntax_dir = config_dir.join("syntax");
|
let syntax_dir = source_dir.join("syntaxes");
|
||||||
|
if !syntax_dir.exists() {
|
||||||
|
return Err(format!(
|
||||||
|
"Could not load syntaxes from '{}'",
|
||||||
|
syntax_dir.to_string_lossy()
|
||||||
|
).into());
|
||||||
|
}
|
||||||
let _ = syntax_set.load_syntaxes(syntax_dir, true);
|
let _ = syntax_set.load_syntaxes(syntax_dir, true);
|
||||||
syntax_set.load_plain_text_syntax();
|
syntax_set.load_plain_text_syntax();
|
||||||
|
|
||||||
@ -77,9 +82,9 @@ impl HighlightingAssets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_binary() -> Self {
|
fn from_binary() -> Self {
|
||||||
let mut syntax_set: SyntaxSet = from_binary(include_bytes!("../assets/syntax_set"));
|
let mut syntax_set: SyntaxSet = from_binary(include_bytes!("../assets/syntaxes.bin"));
|
||||||
syntax_set.link_syntaxes();
|
syntax_set.link_syntaxes();
|
||||||
let theme_set: ThemeSet = from_binary(include_bytes!("../assets/theme_set"));
|
let theme_set: ThemeSet = from_binary(include_bytes!("../assets/themes.bin"));
|
||||||
|
|
||||||
HighlightingAssets {
|
HighlightingAssets {
|
||||||
syntax_set,
|
syntax_set,
|
||||||
@ -87,11 +92,11 @@ impl HighlightingAssets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(&self) -> Result<()> {
|
pub fn save(&self, dir: Option<&Path>) -> Result<()> {
|
||||||
let cache_dir = PROJECT_DIRS.cache_dir();
|
let target_dir = dir.unwrap_or_else(|| PROJECT_DIRS.cache_dir());
|
||||||
let _ = fs::create_dir(cache_dir);
|
let _ = fs::create_dir(target_dir);
|
||||||
let theme_set_path = theme_set_path();
|
let theme_set_path = target_dir.join("themes.bin");
|
||||||
let syntax_set_path = syntax_set_path();
|
let syntax_set_path = target_dir.join("syntaxes.bin");
|
||||||
|
|
||||||
print!(
|
print!(
|
||||||
"Writing theme set to {} ... ",
|
"Writing theme set to {} ... ",
|
||||||
@ -137,11 +142,11 @@ impl HighlightingAssets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn theme_set_path() -> PathBuf {
|
pub fn theme_set_path() -> PathBuf {
|
||||||
PROJECT_DIRS.cache_dir().join("theme_set")
|
PROJECT_DIRS.cache_dir().join("themes.bin")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn syntax_set_path() -> PathBuf {
|
pub fn syntax_set_path() -> PathBuf {
|
||||||
PROJECT_DIRS.cache_dir().join("syntax_set")
|
PROJECT_DIRS.cache_dir().join("syntaxes.bin")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn config_dir() -> Cow<'static, str> {
|
pub fn config_dir() -> Cow<'static, str> {
|
||||||
|
@ -27,6 +27,7 @@ mod terminal;
|
|||||||
|
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::{self, BufRead, BufReader, Write};
|
use std::io::{self, BufRead, BufReader, Write};
|
||||||
|
use std::path::Path;
|
||||||
use std::process::{self, Child, Command, Stdio};
|
use std::process::{self, Child, Command, Stdio};
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@ -206,8 +207,11 @@ fn run() -> Result<()> {
|
|||||||
match app.matches.subcommand() {
|
match app.matches.subcommand() {
|
||||||
("cache", Some(cache_matches)) => {
|
("cache", Some(cache_matches)) => {
|
||||||
if cache_matches.is_present("init") {
|
if cache_matches.is_present("init") {
|
||||||
let assets = HighlightingAssets::from_files()?;
|
let source_dir = cache_matches.value_of("source").map(Path::new);
|
||||||
assets.save()?;
|
let target_dir = cache_matches.value_of("target").map(Path::new);
|
||||||
|
|
||||||
|
let assets = HighlightingAssets::from_files(source_dir)?;
|
||||||
|
assets.save(target_dir)?;
|
||||||
} else if cache_matches.is_present("clear") {
|
} else if cache_matches.is_present("clear") {
|
||||||
print!("Clearing theme set cache ... ");
|
print!("Clearing theme set cache ... ");
|
||||||
fs::remove_file(theme_set_path()).ok();
|
fs::remove_file(theme_set_path()).ok();
|
||||||
|
Loading…
Reference in New Issue
Block a user