X-Git-Url: https://git.armaanb.net/?p=charsel.git;a=blobdiff_plain;f=src%2Fcharsel;h=84c0affc7a0a26d9ff8fb028377a1d871ee3b5aa;hp=fe185a4676406434d3ec7d81f73d9a38ab92b72a;hb=a83d035291f0d6f0f33923972ffd67a25a069219;hpb=80b5946548fcc4087fb7af79b1bda98d6985338f diff --git a/src/charsel b/src/charsel index fe185a4..84c0aff 100755 --- a/src/charsel +++ b/src/charsel @@ -1,44 +1,34 @@ -# 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 . - -#!/usr/bin/env sh +#!/usr/bin/env bash # Merge both global and local charfiles -CHARDIR=/tmp/charsel -cp -R /usr/share/charsel/* $CHARDIR/ -cp -R ~/.local/share/* $CHARDIR/ +CHARDIR=~/.cache/charsel -# Clear screen -clear +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 -[ -z "$1" ] && echo "No argument supplied" && exit - if [ $1 = "list" ]; then echo "The following charfiles are installed" ls $CHARDIR/charfiles exit +elif [[ $1 = "help" || $1 = "-h" || $1 = "--help" || $# -ne 1 ]]; then + cat /usr/share/doc/charsel/README.md + exit else -# Define charfile +# Clear screen +clear + +# Define charfile path CHARFILE=$CHARDIR/charfiles/$1 # Define length of shortcut LENGTH=$(cat $CHARFILE | cut -f 1 -d ',' -s | wc -L | cut -b 1) # MOTD -cat /tmp/charsel/motd +cat $CHARDIR/motd # Main program while : @@ -50,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