From 23462855da29a6a5cde4110e7dc339d96fa36e45 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me> Date: Mon, 2 Nov 2020 13:54:04 -0500 Subject: [PATCH] combined files --- .gitignore | 33 ----------------------- README.md | 26 +++++++++---------- src/CMakeLists.txt | 3 +-- src/main.cpp | 42 ++++++++++++++++++++++++++---- src/prompt.cpp | 65 ---------------------------------------------- 5 files changed, 51 insertions(+), 118 deletions(-) delete mode 100644 src/prompt.cpp diff --git a/.gitignore b/.gitignore index 968076e..6010c67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,38 +1,20 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/cmake,linux,c++ -# Edit at https://www.toptal.com/developers/gitignore?templates=cmake,linux,c++ - -### C++ ### -# Prerequisites *.d - -# Compiled Object files *.slo *.lo *.o *.obj - -# Precompiled Headers *.gch *.pch - -# Compiled Dynamic libraries *.so *.dylib *.dll *.a - -# Fortran module files *.mod *.smod - -# Executables *.exe *.out *.app gen-shell - -### CMake ### CMakeLists.txt.user CMakeCache.txt CMakeFiles @@ -48,24 +30,9 @@ CPackConfig.cmake CPackSourceConfig.cmake commit.h commit.h.in - -### CMake Patch ### -# External projects *-prefix/ - -### Linux ### *~ - -# temporary files which can be created if a process still has a handle open of a deleted file .fuse_hidden* - -# KDE directory preferences .directory - -# Linux trash folder which might appear on any partition or disk .Trash-* - -# .nfs files are created when an open file is removed but is still being accessed .nfs* - -# End of https://www.toptal.com/developers/gitignore/api/cmake,linux,c++ diff --git a/README.md b/README.md index b696a29..481053d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # gen-shell ![Jenkins](https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fbuild.bhojwani.org%2Fjob%2Fgen-shell%2F) -A simple way to turn any command into a shell with arrow key/history support. This is a fork of [taskshell](https://github.com/GothenburgBitFactory/taskshell) with a highly reduce codebase. +A simple way to turn any command into a shell with arrow key/history support (if compiled with libreadline). Forked from [taskshell](https://github.com/GothenburgBitFactory/taskshell). ## Usage -Just put the command that you want to repeat after the c flag, eg; `gen-shell -c ls`, or even something much more complex like `gen-shell -c "cd /home/armaa/Clone/words && /home/armaa/Clone/words/bin/words` This command was actually the inspiration for gen-shell. +Just put the command that you want to repeat after the c flag, eg; `gen-shell -c ls`, or even something much more complex like `gen-shell -c "cd /home/armaa/Clone/words && /home/armaa/Clone/words/bin/words"` This command was actually the inspiration for gen-shell. ## Installation -### Binaries +### From a binary Binaries can be downloaded [from here](https://build.bhojwani.org/job/gen-shell/lastSuccessfulBuild/artifact/build/src/gen-shell). NB: these binaries are compiled against libreadline7, so if your system only has libreadline8, you can symlink 8 to 7 with `sudo ln -s /usr/lib/x86_64-linux-gnu/libreadline.so.8.0 /usr/lib/x86_64-linux-gnu/libreadline.so.7`. This isn't a great solution, but it gets the job done. ### From source @@ -15,14 +15,14 @@ If you would like to avoid this, you can build from source. Doing so requires: - make - gcc - g++ (sometimes packaged as gcc-c++ or gcc-g++) - - cpp (11 or higher) - - libreadline development files (7 or 8 is fine, 5 is untested) + - cpp (any somewhat recent version is fine) + - libreadline development files (7 or 8 is fine, 5 is untested) (optional, but highly reccomended) On a Debian or Ubuntu based distribution, you can install these dependencies with this command: ```bash sudo apt update && sudo apt install cmake make gcc g++ cpp libreadline-dev ``` - +Then download and build gen shell: ```bash git clone --recursive https://codeberg.org/armaan/gen-shell cd gen-shell @@ -30,22 +30,22 @@ cmake . make sudo cp src/gen-shell /usr/bin/ ``` -Or if you don't have root access, you can subsitute the last line with +Or, if you don't have root access, you can subsitute the last line with `cp src/gen-shell ~/.local/bin` ### Docker You can also run gen-shell in docker. Simply use ```bash -docker run -it -e CMD= armaanb/gen-shell:latest +docker run -it -e CMD= armaanb/gen-shell ``` -Or to build the docker container locally, which ensures that you are using the latest version, or lets you make changes to the source code before building: +Or to build the docker container locally, run: ```bash git clone --recursive https:/codeberg.org/armaan/gen-shell cd gen-shell -docker build --no-cache -t armaanb/gen-shell:latest . -docker run -it -e CMD= armaanb/gen-shell +docker build --no-cache -t gen-shell:latest . +docker run -it -e CMD= gen-shell ``` ## License -Following suit from tasksh, gen-shell is MIT licensed by Armaan Bhojwani, 2020. Gen-shell is forked from tasksh, from which its codebase has been greatly reduced, although the majority of code remaining was written by the tasksh developers [(listed here)](https://github.com/GothenburgBitFactory/taskshell/blob/master/AUTHORS). +Following suit from taskshell, gen-shell is MIT licensed by Armaan Bhojwani, 2020. Gen-shell is forked from taskshell, which was developed by [these people](https://github.com/GothenburgBitFactory/taskshell/blob/master/AUTHORS). -Gen-shell uses [Sarge](https://github.com/MayaPosch/Sarge) for parsing command-line arguments. Sarge was written by Maya Posch and is BSD 3-Clause licensed +Gen-shell uses the [Sarge library](https://github.com/MayaPosch/Sarge) for parsing command-line arguments. Sarge was written by Maya Posch and is BSD 3-Clause licensed. It is added as a submodule in the root folder of this repository. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e67bb26..841ad0f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,8 +3,7 @@ include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src ${GEN-SHELL_INCLUDE_DIRS}) -set (gen-shell_SRCS prompt.cpp - ../Sarge/src/sarge.cpp) +set (gen-shell_SRCS ../Sarge/src/sarge.cpp) add_library (gen-shell STATIC ${gen-shell_SRCS}) diff --git a/src/main.cpp b/src/main.cpp index 1e8f1d2..3d0e2c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,8 @@ #include #include +#include +#include #include <../Sarge/src/sarge.h> #include @@ -39,19 +41,49 @@ using namespace std; std::string promptCompose(); +static std::vector contexts; +std::string composeContexts (bool pretty = false); + +int promptClear () +{ + contexts.clear (); + return 0; +} + +int promptRemove () +{ + if (contexts.size ()) + contexts.pop_back (); + + return 0; +} + +int promptAdd (const std::string& context) +{ + contexts.push_back (context); + return 0; +} + +std::string promptCompose () +{ + return "% "; +} + +//////////////////////////////////////////////////////////////////////////////// + const std::string getResponse(const std::string & prompt) { std::string response { "" }; - // Display prompt, get input. + // Display prompt, get input #ifdef HAVE_READLINE char * line_read = readline(prompt.c_str()); if (!line_read) { std::cout << "\n"; response = ""; } else { - // Save history. + // Save history if ( * line_read) add_history(line_read); @@ -99,15 +131,15 @@ int main(int argc, char** argv) // Main program while (true) { - // Compose the prompt. + // Compose the prompt auto prompt = promptCompose(); - // Display prompt, get input. + // Display prompt, get input auto command = getResponse(prompt); if (command != "") { - // Dispatch command. + // Dispatch command if (command == "") { return 0; diff --git a/src/prompt.cpp b/src/prompt.cpp deleted file mode 100644 index 493425a..0000000 --- a/src/prompt.cpp +++ /dev/null @@ -1,65 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// 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 -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include - -//////////////////////////////////////////////////////////////////////////////// - -static std::vector contexts; -std::string composeContexts (bool pretty = false); - -int promptClear () -{ - contexts.clear (); - return 0; -} - -int promptRemove () -{ - if (contexts.size ()) - contexts.pop_back (); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// - -int promptAdd (const std::string& context) -{ - contexts.push_back (context); - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// - -std::string promptCompose () -{ - return "% "; -} - -//////////////////////////////////////////////////////////////////////////////// -- 2.39.2