]> git.armaanb.net Git - charsel.git/blobdiff - src/charsel
fixed excess copying
[charsel.git] / src / charsel
index 6713b599d56b097afc7931b652aa97c0a132f1eb..84c0affc7a0a26d9ff8fb028377a1d871ee3b5aa 100755 (executable)
@@ -1,24 +1,12 @@
-# Copyright 2020 Armaan Bhojwani
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-
-#!/usr/bin/env sh
+#!/usr/bin/env bash
 # Merge both global and local charfiles
 CHARDIR=~/.cache/charsel
-mkdir $CHARDIR/
-cp -R /usr/share/charsel/* $CHARDIR/
-cp -R ~/.local/share/charsel/* $CHARDIR/
+
+if [[ ! "$(ls -A $CHARDIR)" || ! -d $CHARDIR ]]; then
+  mkdir $CHARDIR/
+  cp -R /usr/share/charsel/* $CHARDIR/
+  cp -R ~/.local/share/charsel/* $CHARDIR/
+fi
 
 # Check if user provided an input
 if [ $1 = "list" ]; then
@@ -52,8 +40,8 @@ do
   read -N $LENGTH INPUT
   
   # Navigate to the right characther
-  OUTPUT=$(grep $INPUT $CHARFILE | cut -f 2 -d ',' -s)
-
+  LINENUMBER=$(cut -f 1 -d ',' -s $CHARFILE | grep -n $INPUT | cut -d : -f 1)
+  OUTPUT=$(cut -f 2 -d ',' -s $CHARFILE | head -$LINENUMBER | tail +$LINENUMBER)
   # Clear screen
   clear