From dfb36bf9065c4699c46cfbee9acfb694bd044386 Mon Sep 17 00:00:00 2001
From: Tom Almeida <tommoa256@gmail.com>
Date: Thu, 24 Jan 2019 11:20:39 +1100
Subject: [PATCH] Add the ability to use numbers for indexing map types

---
 src/lib/shell/mod.rs | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/lib/shell/mod.rs b/src/lib/shell/mod.rs
index 3192ee9e..7a409d23 100644
--- a/src/lib/shell/mod.rs
+++ b/src/lib/shell/mod.rs
@@ -496,6 +496,17 @@ impl<'a> Expander for Shell {
                         hmap.get(&*key).unwrap_or(&VariableType::Str("".into()))
                     )])
                 }
+                Select::Index(index) => {
+                    use ranges::Index;
+                    return Some(array![format!(
+                        "{}",
+                        hmap.get(&types::Str::from(match index {
+                            Index::Forward(n) => n as isize,
+                            Index::Backward(n) => -((n+1) as isize)
+                        }.to_string()))
+                        .unwrap_or(&VariableType::Str("".into()))
+                    )])
+                }
                 _ => (),
             }
         } else if let Some(bmap) = self.variables.get::<types::BTreeMap>(name) {
@@ -525,6 +536,17 @@ impl<'a> Expander for Shell {
                         bmap.get(&*key).unwrap_or(&VariableType::Str("".into()))
                     )])
                 }
+                Select::Index(index) => {
+                    use ranges::Index;
+                    return Some(array![format!(
+                        "{}",
+                        bmap.get(&types::Str::from(match index {
+                            Index::Forward(n) => n as isize,
+                            Index::Backward(n) => -((n+1) as isize)
+                        }.to_string()))
+                        .unwrap_or(&VariableType::Str("".into()))
+                    )])
+                }
                 _ => (),
             }
         }
-- 
GitLab