]> git.armaanb.net Git - gen-shell.git/blobdiff - src/main.cpp
move to sr.ht, minor updates
[gen-shell.git] / src / main.cpp
index 6e14fe4a8c4d0ecaa043e4bf7a88bdb9f46d1d78..144d9069980d49f770aa64e07896370fb3c55eb0 100644 (file)
@@ -1,37 +1,12 @@
-////////////////////////////////////////////////////////////////////////////////
-//
-// gen-shell, the generic shell
-//
-// Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez,
-// 2020, Armaan Bhojwani
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-// SOFTWARE.
-//
-// http://www.opensource.org/licenses/mit-license.php
-//
-////////////////////////////////////////////////////////////////////////////////
-
+// gen-shell - the generic shell
+// Copyright (c) 2020, Armaan Bhojwani <code@armaanb.net>
 
 #include <cmake.h>
 #include <iostream>
 #include <../Sarge/src/sarge.h>
-#include <stdlib.h>
+#include <filesystem>
+#include <vector>
+#include <string>
 
 #ifdef HAVE_READLINE
   #include <readline/readline.h>
@@ -41,6 +16,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 using namespace std;
+using std::filesystem::exists;
 
 const std::string getResponse(const std::string & prompt) {
   std::string response {
@@ -130,14 +106,23 @@ int main(int argc, char** argv)
   string after_command;
   sarge.getFlag("after", after_command);
 
+  string alias_file
+  vector<string> alias_files = {"$XDG_CONFIG_HOME/gen-shell/aliases",
+                                "$HOME/.config/gen-shell/aliases"};
+  for(const auto &file : alias_files)
+  {
+    if (exists(file))
+    {
+      alias_file = file;
+      break;
+    }
+  }
+
   // Do the stuffs!
   while (true) {
-    // Display prompt, get input
     auto command = getResponse(prompt);
 
-    // Dispatch command
     if (command == "<EOF>" || command == "exit" || command == "quit" )
-    // if (command == "<EOF>" || command == "exit" )
     {
       system (after_command.c_str ());
       return 0;