diff --git a/README.md b/README.md index 0a135917dfd336951f4ff60a89a4061e506b0547..4df5ef2e360fe392881110fd9d567ec9fc394667 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,11 @@ # New Ion MdBook -See the **manual** directory contained within the repository. Navigating to that directory and executing `mdbook build` will build HTML documentation for Ion. -Obtain mdbook [here](https://github.com/azerupi/mdBook). +We are providing our manual for Ion in the form of a markdown-based book, which is accessible via: + +- The official page for Ion's manual on Redox's website: https://doc.redox-os.org/ion-manual/ +- Installing the mdbook via our `setup.ion` script and having Ion open an offline copy via `ion-docs`. +- Building and serving the book in the **manual** directory in the yourself with [mdBook](https://github.com/azerupi/mdBook) # Introduction @@ -101,14 +104,9 @@ To install the git plugin, first install ion, and then execute the following: It can be tested out by navigating to a directory within a git repository, and running the following: ```ion -echo Current Branch: ${git::branch} +echo Current Branch: ${git::branch}${git::modified_count}${git::untracked_count} ``` -# Install Documentation - -The mdBook shipping with Ion can be installed into the system and accessed via the `ion-docs` builtin. -See the `setup.ion` script in this repository (execute it without arguments to get more info). - # Vim/NeoVim Syntax Highlighting Plugin We do have an [officially-supported syntax highlighting plugin](https://github.com/vmchale/ion-vim) for all the diff --git a/src/main.rs b/src/main.rs index 950f5e584468dbbb540ba2125dd3ecb560dba423..b1540850e82fda5916a4ec27c0e641fc9decace6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ extern crate app_dirs; #[macro_use] extern crate bitflags; +extern crate unicode_segmentation; extern crate fnv; extern crate glob; #[macro_use] diff --git a/src/parser/shell_expand/mod.rs b/src/parser/shell_expand/mod.rs index 8e4180b13d722dae9a9d0f121d6f3930d4f06b48..345f2205050ba0324d588dbf80cfe16bb4a8dbcc 100644 --- a/src/parser/shell_expand/mod.rs +++ b/src/parser/shell_expand/mod.rs @@ -1,8 +1,7 @@ // TODO: Handle Runtime Errors extern crate permutate; -extern crate unicode_segmentation; extern crate calc; -use self::unicode_segmentation::UnicodeSegmentation; +use unicode_segmentation::UnicodeSegmentation; use types::Array; diff --git a/src/parser/shell_expand/words.rs b/src/parser/shell_expand/words.rs index ec69e85e60f50f8e638207e3018f840b345fd915..c7aaffbc998d55ddff2c8dfcf1ec431f44ba8312 100644 --- a/src/parser/shell_expand/words.rs +++ b/src/parser/shell_expand/words.rs @@ -8,7 +8,7 @@ use super::{Expander, expand_string}; use super::{is_expression, slice}; use super::ranges::parse_index_range; use super::super::ArgumentSplitter; -use super::unicode_segmentation::UnicodeSegmentation; +use unicode_segmentation::UnicodeSegmentation; use shell::plugins::methods::{self, StringMethodPlugins, MethodArguments}; use std::path::Path; diff --git a/src/shell/variables.rs b/src/shell/variables/mod.rs similarity index 84% rename from src/shell/variables.rs rename to src/shell/variables/mod.rs index a471f289fab8a4aede875e1267acf8bfdf8a1273..19355acc0f3071280e5de1780369c61e3a98fa82 100644 --- a/src/shell/variables.rs +++ b/src/shell/variables/mod.rs @@ -8,6 +8,7 @@ use std::env; use std::io::{self, BufRead}; use std::process; use types::{Array, ArrayVariableContext, HashMap, HashMapVariableContext, Identifier, Key, Value, VariableContext}; +use unicode_segmentation::UnicodeSegmentation; #[cfg(target_os = "redox")] use sys::getpid; @@ -15,9 +16,9 @@ use sys::getpid; #[cfg(all(unix, not(target_os = "unix")))] use sys::getpid; +use super::colors::Colors; use sys; use sys::variables as self_sys; -use super::colors::Colors; lazy_static! { static ref STRING_NAMESPACES: FnvHashMap<Identifier, StringNamespace> = namespaces::collect(); @@ -37,7 +38,10 @@ impl Default for Variables { map.insert("DIRECTORY_STACK_SIZE".into(), "1000".into()); map.insert("HISTORY_SIZE".into(), "1000".into()); map.insert("HISTFILE_SIZE".into(), "1000".into()); - map.insert("PROMPT".into(), "${c::0x55,bold}${USER}${c::default}:${c::0x4B}${PWD}${c::default}# ${c::reset}".into()); + map.insert( + "PROMPT".into(), + "${c::0x55,bold}${USER}${c::default}:${c::0x4B}${SWD}${c::default}# ${c::reset}".into(), + ); // Set the PID variable to the PID of the shell let pid = getpid().map(|p| p.to_string()).unwrap_or_else( |e| e.to_string(), @@ -144,7 +148,52 @@ impl Variables { pub fn unset_array(&mut self, name: &str) -> Option<Array> { self.arrays.remove(name) } + /// Obtains the value for the **SWD** variable. + /// + /// Useful for getting smaller prompts, this will produce a simplified variant of the + /// working directory which the leading `HOME` prefix replaced with a tilde character. + fn get_simplified_directory(&self) -> Value { + self.get_var("PWD").unwrap().replace(&self.get_var("HOME").unwrap(), "~") + } + + /// Obtains the value for the **MWD** variable. + /// + /// Further minimizes the directory path in the same manner that Fish does by default. + /// That is, if more than two parents are visible in the path, all parent directories + /// of the current directory will be reduced to a single character. + fn get_minimal_directory(&self) -> Value { + let swd = self.get_simplified_directory(); + + { + // Temporarily borrow the `swd` variable while we attempt to assemble a minimal + // variant of the directory path. If that is not possible, we will cancel the + // borrow and return `swd` itself as the minified path. + let elements = swd.split("/").collect::<Vec<&str>>(); + if elements.len() > 2 { + let mut output = String::new(); + for element in &elements[0..elements.len()-1] { + let mut segmenter = UnicodeSegmentation::graphemes(*element, true); + let grapheme = segmenter.next().unwrap(); + output.push_str(grapheme); + if grapheme == "." { + output.push_str(segmenter.next().unwrap()); + } + output.push('/'); + } + output.push_str(&elements[elements.len()-1]); + return output; + } + } + + swd + } + pub fn get_var(&self, name: &str) -> Option<Value> { + match name { + "SWD" => return Some(self.get_simplified_directory()), + "MWD" => return Some(self.get_minimal_directory()), + _ => (), + } if let Some((name, variable)) = name.find("::").map(|pos| (&name[..pos], &name[pos + 2..])) { // If the parsed name contains the '::' pattern, then a namespace was designated. Find it. match name {