mirror of
				https://github.com/sharkdp/bat.git
				synced 2025-11-04 00:51:56 +00:00 
			
		
		
		
	@@ -2,4 +2,4 @@
 | 
			
		||||
 | 
			
		||||
ASSET_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 | 
			
		||||
 | 
			
		||||
bat cache --init --source="$ASSET_DIR" --target="$ASSET_DIR"
 | 
			
		||||
bat cache --init --blank --source="$ASSET_DIR" --target="$ASSET_DIR"
 | 
			
		||||
 
 | 
			
		||||
@@ -210,6 +210,12 @@ impl App {
 | 
			
		||||
                            .help(
 | 
			
		||||
                                "Use a different directory to store the cached syntax and theme set",
 | 
			
		||||
                            ),
 | 
			
		||||
                    ).arg(
 | 
			
		||||
                        Arg::with_name("blank")
 | 
			
		||||
                            .long("blank")
 | 
			
		||||
                            .requires("init")
 | 
			
		||||
                            .help("Create completely new syntax and theme sets \
 | 
			
		||||
                                   (instead of appending to the default sets")
 | 
			
		||||
                    ),
 | 
			
		||||
            ).help_message("Print this help message.")
 | 
			
		||||
            .version_message("Show version information.")
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
use directories::ProjectDirs;
 | 
			
		||||
use errors::*;
 | 
			
		||||
use std::borrow::Cow;
 | 
			
		||||
use std::collections::BTreeMap;
 | 
			
		||||
use std::fs::{self, File};
 | 
			
		||||
use std::path::{Path, PathBuf};
 | 
			
		||||
use syntect::dumps::{dump_to_file, from_binary, from_reader};
 | 
			
		||||
@@ -25,10 +26,27 @@ impl HighlightingAssets {
 | 
			
		||||
        Self::from_cache().unwrap_or_else(|_| Self::from_binary())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn from_files(dir: Option<&Path>) -> Result<Self> {
 | 
			
		||||
    fn empty() -> Self {
 | 
			
		||||
        let mut syntax_set = SyntaxSet::new();
 | 
			
		||||
        syntax_set.load_plain_text_syntax();
 | 
			
		||||
 | 
			
		||||
        let theme_set = ThemeSet {
 | 
			
		||||
            themes: BTreeMap::new(),
 | 
			
		||||
        };
 | 
			
		||||
        HighlightingAssets {
 | 
			
		||||
            syntax_set,
 | 
			
		||||
            theme_set,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn from_files(dir: Option<&Path>, start_empty: bool) -> Result<Self> {
 | 
			
		||||
        let source_dir = dir.unwrap_or_else(|| PROJECT_DIRS.config_dir());
 | 
			
		||||
 | 
			
		||||
        let mut assets = Self::from_binary_unlinked();
 | 
			
		||||
        let mut assets = if start_empty {
 | 
			
		||||
            Self::empty()
 | 
			
		||||
        } else {
 | 
			
		||||
            Self::from_binary_unlinked()
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        let theme_dir = source_dir.join("themes");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -73,7 +73,9 @@ fn run() -> Result<bool> {
 | 
			
		||||
                let source_dir = cache_matches.value_of("source").map(Path::new);
 | 
			
		||||
                let target_dir = cache_matches.value_of("target").map(Path::new);
 | 
			
		||||
 | 
			
		||||
                let assets = HighlightingAssets::from_files(source_dir)?;
 | 
			
		||||
                let blank = cache_matches.is_present("blank");
 | 
			
		||||
 | 
			
		||||
                let assets = HighlightingAssets::from_files(source_dir, blank)?;
 | 
			
		||||
                assets.save(target_dir)?;
 | 
			
		||||
            } else if cache_matches.is_present("clear") {
 | 
			
		||||
                clear_assets();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user