aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2016-10-31 12:27:43 +0100
committerRahiel Kasim <rahielkasim@gmail.com>2016-10-31 12:27:43 +0100
commit10569f3709062cc8564a06f22e83931324438208 (patch)
treeda039db09ff9793da1fb5e94fbf2c822d11db4a5
parent4b1917aecec5e56313fd65bd5b727ece9609e1a6 (diff)
show first two chars for hidden directories
so for example .config and .local are distinguishable
-rw-r--r--Cargo.toml2
-rw-r--r--README.md3
-rw-r--r--src/main.rs12
3 files changed, 12 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 4938d58..b166d15 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "pwds"
-version = "0.1.0"
+version = "0.2.0"
authors = ["Rahiel Kasim <rahielkasim@gmail.com>"]
license = "Apache-2.0"
readme = "README.md"
diff --git a/README.md b/README.md
index ff55bcd..1594ffb 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,9 @@ The current working directory in your prompt can get uncomfortably large,
leaving little space to type your own commands. With pwds paths like
`/home/user/Code/rust/src/doc/nomicon` are displayed as `~/C/r/s/d/nomicon`.
+It shows the first two characters for (hidden) directories that start with a
+".". So `/home/rahiel/.config/autostart` becomes `~/.c/autostart`.
+
# Installation
Install pwds with cargo:
diff --git a/src/main.rs b/src/main.rs
index 23c6e22..ca68b0c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -50,10 +50,14 @@ fn main() {
let char_count = dirs[i].chars().count();
if char_count > 1 {
length = length - char_count + 1;
- let mut chars = dirs[i].char_indices();
- let start = chars.next().unwrap().0;
- let end = chars.next().unwrap().0;
- dirs[i] = &dirs[i][start..end];
+ let mut chars = dirs[i].char_indices(); // iterator with (position, char) tuples
+ let start = chars.next().unwrap();
+ let mut end = chars.next().unwrap();
+ if start.1 == '.' { // show an extra char for hidden directories
+ length += 1;
+ end = chars.next().unwrap();
+ }
+ dirs[i] = &dirs[i][start.0..end.0];
}
i = i + 1;
}