]> git.armaanb.net Git - charsel.git/blobdiff - src/charsel
More foolproof method
[charsel.git] / src / charsel
index 80909d3f2751f49aa0fb01836801cefb0238954a..f435fde43882656299509420f85f32cf44f3b298 100755 (executable)
@@ -1,21 +1,7 @@
-# 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=/tmp/charsel
+CHARDIR=~/.cache/charsel
+mkdir $CHARDIR/
 cp -R /usr/share/charsel/* $CHARDIR/
 cp -R ~/.local/share/charsel/* $CHARDIR/
 
@@ -39,7 +25,7 @@ CHARFILE=$CHARDIR/charfiles/$1
 LENGTH=$(cat $CHARFILE | cut -f 1 -d ',' -s | wc -L | cut -b 1)
 
 # MOTD
-cat /tmp/charsel/motd
+cat $CHARDIR/motd
 
 # Main program
 while :
@@ -51,8 +37,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