summaryrefslogtreecommitdiffstats
path: root/src/poem/anthology/cd.rs
blob: 3b48f602882f9b38279e55ae45430b437d987031 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use crate::poem::Verse;

pub fn incant(verse: &Verse) -> i32 {
    let path = match verse.clause() {
        Some(path) => path[0].to_string(),
        None => env!("HOME").to_string(),
    };

    match std::env::set_current_dir(&path) {
        Ok(_) => 0,
        Err(e) => {
            eprintln!(
                "cd: unable to change into {}: {}",
                path,
                e.to_string().to_lowercase()
            );
            1
        }
    }
}