From 8912743440cf6de118609a89c26e5cd665c67241 Mon Sep 17 00:00:00 2001
From: Madiwka4 <madi.turgunov.03@gmail.com>
Date: Fri, 31 Jul 2020 11:37:27 +0600
Subject: [PATCH] Added customizable editors in setup

---
 README.md |  5 +++--
 setup.sh  | 33 +++++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index 8b95679..154f18a 100644
--- a/README.md
+++ b/README.md
@@ -14,8 +14,9 @@ cd cpsrc
 chmod +x setup.sh
 ./setup.sh
 ```
-
-First, you are given the choise to enter your custom directory, for example, 
+First, you have to choose your default text editor. You can set any editor you want, as long as it supports opening files using the "editor file" type shell command. 
+Then, you can choose the package name of the editor. This makes sure that the editor is up to date. 
+After that, you are given the choise to enter your custom directory, for example, 
 
 ```
 Enter custom directory for code? [y/N] y
diff --git a/setup.sh b/setup.sh
index 0ba57ae..975d192 100755
--- a/setup.sh
+++ b/setup.sh
@@ -1,16 +1,33 @@
+echo "Your preferred text editor (type in package that will be used, as per your package manager:"
+read editor 
+
+echo "Set your editor as $editor" 
+read -r -p "${1:-Is your editor's package name different from its binary name (e.g. python-pip and pip)? [y/N]} " response
+case "$response" in
+    [yY][eE][sS]|[yY]) 
+    echo "Enter your editor's package name"
+    read editorPACKAGE
+    echo "set editor PACKAGE as $editorPACKAGE"
+        ;;
+    *)  
+        editorPACKAGE=$editor 
+        echo "Setting editor PACKAGE as $editorPACKAGE"
+        
+        ;;
+esac
 echo "Your distro? ( 1)Arch, 2)Debian): "
 read distro
 if [ $distro -eq 1 ]
 then 
-    sudo pacman -Syu g++ code
+    sudo pacman -Syu g++ $editorPACKAGE  
 elif [ $distro -eq 2 ]
 then
     sudo apt update
     sudo apt upgrade 
-    sudo apt install g++ code
+    sudo apt install g++ $editorPACKAGE
 	
 else 
-    echo "Please install these packages manually: Code, G++"
+    echo "Please install/update these packages manually: $editorPACKAGE, G++"
     read -p "Press enter to continue" A	
 fi
 
@@ -22,16 +39,20 @@ fi
 		echo "set dir as $DIR"
             ;;
         *)
-            echo "Setting this directory"
+            DIR='.'
+            echo "Setting this directory ($DIR)"
             ;;
     esac
 
 # create.sh
-echo 'cp template.cpp $1.cpp \n code $1.cpp' > $DIR/create.sh
+echo 'cp template.cpp $1.cpp \n' > $DIR/create.sh
+printf "$editor " >> $DIR/create.sh
+printf '$1.cpp ' >> $DIR/create.sh  
+
 
 # template
 read -p "Press enter to create template" A
-code $DIR/template.cpp
+$editor $DIR/template.cpp
 
 # run.sh
 echo 'g++ -o $1.out -g $1.cpp\n./$1.out' > $DIR/run.sh