pub struct ScriptTypeConfig {
    pub ext: Option<String>,
    pub color: String,
    pub cmd: Option<String>,
    /* private fields */
}

Fields§

§ext: Option<String>§color: String§cmd: Option<String>

Implementations§

Examples found in repository?
src/util/main_util.rs (line 188)
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
fn run(
    script_path: &Path,
    info: &ScriptInfo,
    remaining: &[String],
    hs_tmpl_val: &serde_json::Value,
    remaining_envs: &[EnvPair],
) -> Result<()> {
    let conf = Config::get();
    let ty = &info.ty;

    let script_conf = conf.get_script_conf(ty)?;
    let cmd_str = if let Some(cmd) = &script_conf.cmd {
        cmd
    } else {
        return Err(Error::PermissionDenied(vec![script_path.to_path_buf()]));
    };

    let env = conf.gen_env(&hs_tmpl_val)?;
    let ty_env = script_conf.gen_env(&hs_tmpl_val)?;

    let pre_run_script = prepare_pre_run(None)?;
    let (cmd, shebang) = super::shebang_handle::handle(&pre_run_script)?;
    let args = shebang
        .iter()
        .map(|s| s.as_ref())
        .chain(std::iter::once(pre_run_script.as_os_str()))
        .chain(remaining.iter().map(|s| s.as_ref()));

    let set_cmd_envs = |cmd: &mut Command| {
        cmd.envs(ty_env.iter().map(|(a, b)| (a, b)));
        cmd.envs(env.iter().map(|(a, b)| (a, b)));
        cmd.envs(remaining_envs.iter().map(|p| (&p.key, &p.val)));
    };

    let mut cmd = super::create_cmd(cmd, args);
    set_cmd_envs(&mut cmd);

    let stat = super::run_cmd(cmd)?;
    log::info!("預腳本執行結果:{:?}", stat);
    if !stat.success() {
        // TODO: 根據返回值做不同表現
        let code = stat.code().unwrap_or_default();
        return Err(Error::PreRunError(code));
    }

    let args = script_conf.args(&hs_tmpl_val)?;
    let full_args = args
        .iter()
        .map(|s| s.as_str())
        .chain(remaining.iter().map(|s| s.as_str()));

    let mut cmd = super::create_cmd(&cmd_str, full_args);
    set_cmd_envs(&mut cmd);

    let stat = super::run_cmd(cmd)?;
    log::info!("程式執行結果:{:?}", stat);
    if !stat.success() {
        let code = stat.code().unwrap_or_default();
        Err(Error::ScriptError(code))
    } else {
        Ok(())
    }
}
Examples found in repository?
src/util/main_util.rs (line 161)
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
fn run(
    script_path: &Path,
    info: &ScriptInfo,
    remaining: &[String],
    hs_tmpl_val: &serde_json::Value,
    remaining_envs: &[EnvPair],
) -> Result<()> {
    let conf = Config::get();
    let ty = &info.ty;

    let script_conf = conf.get_script_conf(ty)?;
    let cmd_str = if let Some(cmd) = &script_conf.cmd {
        cmd
    } else {
        return Err(Error::PermissionDenied(vec![script_path.to_path_buf()]));
    };

    let env = conf.gen_env(&hs_tmpl_val)?;
    let ty_env = script_conf.gen_env(&hs_tmpl_val)?;

    let pre_run_script = prepare_pre_run(None)?;
    let (cmd, shebang) = super::shebang_handle::handle(&pre_run_script)?;
    let args = shebang
        .iter()
        .map(|s| s.as_ref())
        .chain(std::iter::once(pre_run_script.as_os_str()))
        .chain(remaining.iter().map(|s| s.as_ref()));

    let set_cmd_envs = |cmd: &mut Command| {
        cmd.envs(ty_env.iter().map(|(a, b)| (a, b)));
        cmd.envs(env.iter().map(|(a, b)| (a, b)));
        cmd.envs(remaining_envs.iter().map(|p| (&p.key, &p.val)));
    };

    let mut cmd = super::create_cmd(cmd, args);
    set_cmd_envs(&mut cmd);

    let stat = super::run_cmd(cmd)?;
    log::info!("預腳本執行結果:{:?}", stat);
    if !stat.success() {
        // TODO: 根據返回值做不同表現
        let code = stat.code().unwrap_or_default();
        return Err(Error::PreRunError(code));
    }

    let args = script_conf.args(&hs_tmpl_val)?;
    let full_args = args
        .iter()
        .map(|s| s.as_str())
        .chain(remaining.iter().map(|s| s.as_str()));

    let mut cmd = super::create_cmd(&cmd_str, full_args);
    set_cmd_envs(&mut cmd);

    let stat = super::run_cmd(cmd)?;
    log::info!("程式執行結果:{:?}", stat);
    if !stat.success() {
        let code = stat.code().unwrap_or_default();
        Err(Error::ScriptError(code))
    } else {
        Ok(())
    }
}
Examples found in repository?
src/config.rs (line 135)
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
    fn default() -> Self {
        fn gen_alias(from: &str, after: &[&str]) -> (String, Alias) {
            (
                from.to_owned(),
                Alias {
                    after: after.iter().map(|s| s.to_string()).collect(),
                },
            )
        }
        Config {
            last_modified: None,
            recent: Some(999999), // NOTE: 顯示兩千多年份的資料!
            editor: vec!["vim".to_string()],
            prompt_level: PromptLevel::Smart,
            tag_selectors: vec![
                NamedTagSelector {
                    content: "+pin,util".parse().unwrap(),
                    name: "pin".to_owned(),
                    inactivated: false,
                },
                NamedTagSelector {
                    content: "+all,^hide!".parse().unwrap(),
                    name: "no-hidden".to_owned(),
                    inactivated: false,
                },
                NamedTagSelector {
                    content: "+all,^remove!".parse().unwrap(),
                    name: "no-removed".to_owned(),
                    inactivated: false,
                },
            ],
            main_tag_selector: "+all".parse().unwrap(),
            types: ScriptTypeConfig::default_script_types(),
            alias: [
                gen_alias("la", &["ls", "-a"]),
                gen_alias("ll", &["ls", "-l"]),
                gen_alias("l", &["ls", "--grouping", "none", "--limit", "5"]),
                gen_alias("e", &["edit"]),
                gen_alias("gc", &["rm", "--timeless", "--purge", "-s", "remove", "*"]),
                gen_alias("t", &["tags"]),
                gen_alias("p", &["run", "--previous"]),
                gen_alias("pc", &["=util/historian!", "--sequence", "c", "--show-env"]),
                gen_alias("pr", &["=util/historian!", "--sequence", "r", "--show-env"]),
                gen_alias("purge", &["rm", "--purge"]),
                gen_alias("h", &["=util/historian!", "--show-env"]),
            ]
            .into_iter()
            .collect(),
            env: [
                ("NAME", "{{name}}"),
                ("HS_HOME", "{{home}}"),
                ("HS_CMD", "{{cmd}}"),
                ("HS_RUN_ID", "{{run_id}}"),
                (
                    "HS_TAGS",
                    "{{#each tags}}{{{this}}}{{#unless @last}} {{/unless}}{{/each}}",
                ),
                (
                    "HS_ENV_DESC",
                    "{{#each env_desc}}{{{this}}}{{#unless @last}}\n{{/unless}}{{/each}}",
                ),
                ("HS_EXE", "{{exe}}"),
                ("HS_SOURCE", "{{home}}/.hs_source"),
                ("TMP_DIR", "/tmp"),
            ]
            .into_iter()
            .map(|(k, v)| (k.to_owned(), v.to_owned()))
            .collect(),
        }
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.