diff --git a/README.md b/README.md index 864d36c..860d898 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ # Installation -## Compile it yourself +## "Compile it yourself" way install Rust - [installation instructions](https://www.rust-lang.org/tools/install) @@ -29,32 +29,46 @@ cd into cloned repo compile for your OS && Architecture - `cargo build --release` +move compiled executable to the current directory +- `mv target/release/fumosay .` or `mv target/[target_name]/release/fumosay .` **or** -## Download a pre-compiled version (only amd64 Linux and Windows) +## "Download a pre-compiled version (Linux amd64 only)" way - [Download a version of your choice](https://github.com/Unbewohnte/fumosay/releases) -## After compilation|downloading +unzip +- `unzip [zip_archive_name]` or `7z x [7z_archive_name]` -create a directory where the program will 'sit' -- `mkdir $HOME/fumosay` +cd into unzipped directory +- `cd fumosay/` -retrieve the executable and fumofiles and move them there -- `mv fumosay/target/release/fumo $HOME/fumosay/ && mv fumofiles $HOME/fumosay` +## After compilation|downloading +run installation script +- `chmod +x install.sh && sudo ./install.sh` +**binary file and fumofiles must be in the same directory as install.sh !** **Now you have fumosay installed !** -The next possible step would probably be to add this directory to the $PATH environment variable. - - --- ## Use ``` -./fumosay [message] +fumosay message_here +``` +prints a message with a default fumo.fumo template + +``` +fumosay -f mini.fumo message_here +``` +prints a message with a mini.fumo template. You can add your own fumofiles +in /usr/share/fumosay/fumofiles/ and use them with -f flag + +``` +fumosay -d path/to/your/fumofiles/ -f your_fumo.fumo fumofumo ``` +uses a non-default path to fumofiles and a custom fumofile --- diff --git a/fumofiles/fumo.fumo b/fumofiles/fumo.fumo index 12aa13a..27b1200 100644 --- a/fumofiles/fumo.fumo +++ b/fumofiles/fumo.fumo @@ -7,4 +7,4 @@ jj⑨lll ()_/@V@V@V\_() /@V@V@V@V\ - (_)-----(_) \ No newline at end of file + (_)-----(_) diff --git a/fumofiles/mini.fumo b/fumofiles/mini.fumo new file mode 100644 index 0000000..633484a --- /dev/null +++ b/fumofiles/mini.fumo @@ -0,0 +1,4 @@ + + \ + \ + (ᗜˬᗜ) \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..d8d33d6 --- /dev/null +++ b/install.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# fumosay installation script + +FUMOSAY_BIN_DIR_PATH=/usr/bin/ +FUMOFILES_DIR_PATH=/usr/share/fumosay/fumofiles/ + +# create directories +mkdir -p $FUMOSAY_BIN_DIR_PATH && mkdir -p $FUMOFILES_DIR_PATH + +# copy fumosay binary +if [ -e fumosay ] +then + cp fumosay $FUMOSAY_BIN_DIR_PATH && echo "Copied binary file" +elif [ -e target/x86_64-unknown-linux-musl/release/fumosay ] # For debug purposes. The binary file should be in the same directory as the script !!! +then + cp target/x86_64-unknown-linux-musl/release/fumosay $FUMOSAY_BIN_DIR_PATH && echo "Copied binary from linux-musl directory" +else + echo "Could not find a fumosay binary file" + exit 1 +fi + +# copy fumofiles +if [ -d fumofiles ] +then + cp -r fumofiles/* $FUMOFILES_DIR_PATH && echo "Copied fumofiles" +else + echo "Could not find fumofiles directory" + exit 1 +fi + + +echo "Installation completed" + + diff --git a/src/main.rs b/src/main.rs index 591752b..22c3ec3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,13 @@ use std::fs; -use std::env; +use std::path::Path; use clap::{Arg, App}; /// Indicator of where the message should be in fumofile -pub const MESSAGE_INDICATOR: &str = "!message"; +const MESSAGE_INDICATOR: &str = "!message"; /// Fumofile name of the default fumo -pub const FUMO_DEFAULT: &str = "fumo.fumo"; +const FUMO_DEFAULT: &str = "fumo.fumo"; +/// Default directory where fumofiles are placed +const FUMOFILES_DIR: &str = "/usr/share/fumosay/fumofiles/"; /// Returns a resulting string with `MESSAGE_INDICATOR` replaced with given /// `message`. If `MESSAGE_INDICATOR` is not present in fumofile - the @@ -30,7 +32,19 @@ fn main() { .value_name("fumofile") .help("choose another fumofumo to print") .takes_value(true) - .required(false)) + .required(false) + .default_value(FUMO_DEFAULT) + ) + .arg( + Arg::with_name("fumofiles_directory") + .short("d") + .long("fumofiles_directory") + .value_name("fumofiles_directory_path") + .help("look for fumofiles in given directory instead") + .takes_value(true) + .required(false) + .default_value(FUMOFILES_DIR) + ) .arg( Arg::with_name("message") .short("m") @@ -42,17 +56,15 @@ fn main() { .multiple(true) ).get_matches(); - // default path to the fumofile - - // grab path to exe - let executable_path = env::current_exe().expect("Could not get current exe`s path!"); - // remove the last bit (exe filename) - let executable_dir = executable_path.parent().expect("Could not get exe`s parent directory !"); - // local path to the default fumofile - let fumofile_default_path = std::path::Path::new("fumofiles").join(FUMO_DEFAULT); - // add them together - let fumofile_path = executable_dir.join(fumofile_default_path); - + // process fumofiles directory + + // directory with all fumofiles + let new_fumofiles_dir = matches.value_of("fumofiles_directory").unwrap(); + // name of the fumofile to work with + let fumofile_name = matches.value_of("fumo").unwrap(); + // the whole path to the selected fumo + let fumofile_path = Path::new(&new_fumofiles_dir).join(fumofile_name); + // read fumofile let mut fumofile_contents: String = fs::read_to_string(fumofile_path).expect("Could not find a fumofile!");