Advertisement
metalx1000

Simple FZF BASH shopping list

Sep 1st, 2022
1,721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.56 KB | Source Code | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2022  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. list="$HOME/.mylist.lst"
  21.  
  22. touch "$list"
  23. red=`echo -en "\e[31m"`
  24. normal=`echo -en "\e[0m"`
  25.  
  26. function main(){
  27.   [[ "$1" == "print" ]] && print_list
  28.   menu
  29.   [[ "$item" ]] || exit 1
  30.   [[ "$item" == "NEW ITEM" ]] && new_item
  31.   [[ "$item" == "QUIT" ]] && exit
  32.   item_select
  33. }
  34.  
  35. function menu(){
  36.   l=$(sort -u "$list")
  37.   item="$(echo -e "QUIT\nNEW ITEM\n$l" |fzf)"
  38. }
  39.  
  40. function print_list(){
  41.   sort -u "$list"
  42.   exit
  43. }
  44.  
  45. function new_item(){
  46.   read -p "New Item: " new_item
  47.   echo "$new_item" >> $list
  48.   main
  49. }
  50.  
  51. function item_select(){
  52.   read -n1 -p "Do you want to remove '${red}$item${normal}' from the list? [Y/n]: " a
  53.   echo ""
  54.   [[ "$a" != "n" ]] && sed -i "/^$item$/d" "$list"
  55.   main
  56. }
  57.  
  58. main $*
  59.  
Tags: Linux BASH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement