Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Noémi Shell X
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Automate
Agent sessions
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zsombor Szabó-Antalovszky
Noémi Shell X
Commits
279872b4
Commit
279872b4
authored
5 months ago
by
Zsombor Szabó-Antalovszky
Browse files
Options
Downloads
Patches
Plain Diff
Released update 0.2. See the changelog inside nosh.cpp for more info
parent
715ea204
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
noshx.cpp
+50
-29
50 additions, 29 deletions
noshx.cpp
with
50 additions
and
29 deletions
noshx.cpp
+
50
−
29
View file @
279872b4
...
@@ -30,9 +30,14 @@
...
@@ -30,9 +30,14 @@
*
*
* CHANGELOG
* CHANGELOG
*
*
* Noémi Shell X ver. 0.
1
* Noémi Shell X ver. 0.
2
*
*
* THos version is the first version of the Noémi Shell for UNIX like systems
* This version introduses the cd command. In additon, this version is changing
* the prompt, to be more 'UNIX' like.
* The prompt will now always show the current working directory, without requiring
* the 'pwd' command. The 'pwd' command is NOT removed.
* This version also introduces colors to the terminal, as highlighting. This is NOT syntax highligthing
* that may come in a future update.
*
*
*/
*/
...
@@ -46,9 +51,10 @@
...
@@ -46,9 +51,10 @@
#include
<cstring>
// String operations
#include
<cstring>
// String operations
#include
<regex>
// For grasp filtering
#include
<regex>
// For grasp filtering
#include
<cstdlib>
#include
<cstdlib>
#include
<limits.h>
const
char
VERSION
[]
=
"0.
1
"
;
///< Change version number here for the entire code
const
char
VERSION
[]
=
"0.
2
"
;
///< Change version number here for the entire code
#define STRLEN 100 ///< Max string length
#define STRLEN 100 ///< Max string length
#define WIDTH 10 ///< Width between columns
#define WIDTH 10 ///< Width between columns
...
@@ -57,6 +63,7 @@ char vault[STRLEN]; ///< Storing custom info
...
@@ -57,6 +63,7 @@ char vault[STRLEN]; ///< Storing custom info
using
namespace
std
;
using
namespace
std
;
namespace
fs
=
std
::
filesystem
;
// Declaring functions
// Declaring functions
void
handle_pwd
(
const
vector
<
string
>&
args
);
void
handle_pwd
(
const
vector
<
string
>&
args
);
...
@@ -64,11 +71,11 @@ bool is_builtin_command(const vector<string>& args);
...
@@ -64,11 +71,11 @@ bool is_builtin_command(const vector<string>& args);
void
handle_noemi
(
const
vector
<
string
>&
args
);
void
handle_noemi
(
const
vector
<
string
>&
args
);
void
handle_storage
(
const
vector
<
string
>&
args
);
void
handle_storage
(
const
vector
<
string
>&
args
);
void
handle_now
(
const
vector
<
string
>&
args
);
void
handle_now
(
const
vector
<
string
>&
args
);
void
handle_cd
(
const
vector
<
string
>&
args
);
// To be implemented commands:
// To be implemented commands:
//void handle_list(const vector<string>& args);
//void handle_list(const vector<string>& args);
//void handle_cd(const vector<string>& args);
//void handle_read(const vector<string>& args, string filename);
//void handle_read(const vector<string>& args, string filename);
//void handle_grasp(const vector<string>& args);
//void handle_grasp(const vector<string>& args);
//void handle_tap(const vector<string>& args);
//void handle_tap(const vector<string>& args);
...
@@ -92,7 +99,15 @@ int main() {
...
@@ -92,7 +99,15 @@ int main() {
string
command
;
// Storing command
string
command
;
// Storing command
while
(
true
)
{
while
(
true
)
{
cout
<<
"noshx> "
;
char
buffer
[
PATH_MAX
];
string
cwd
=
getcwd
(
buffer
,
sizeof
(
buffer
));
cout
<<
"
\033
[1;33mnoshx:
\033
[0m"
// Yellow "noshx:"
<<
"
\033
[1;96m"
<<
cwd
<<
"
\033
[0m"
// Bold magenta cwd
<<
">
\033
[0m "
;
// Normal >
getline
(
cin
,
command
);
getline
(
cin
,
command
);
// On 'exit' command
// On 'exit' command
...
@@ -158,14 +173,14 @@ void handle_help(const vector<string>& args){
...
@@ -158,14 +173,14 @@ void handle_help(const vector<string>& args){
<<
"about --version: Displays shell version only
\n
"
<<
"about --version: Displays shell version only
\n
"
<<
"exec: Execute an executable file
\n
"
<<
"exec: Execute an executable file
\n
"
<<
"exit: Exit the shell
\n
"
<<
"exit: Exit the shell
\n
"
<<
"grasp -d: Search through directories for other directories
\n
"
//
<< "grasp -d: Search through directories for other directories\n"
<<
"grasp -f: Search through directories for files
\n
"
//
<< "grasp -f: Search through directories for files\n"
<<
"list: List the files or other directories whithin a directory
\n
"
//
<< "list: List the files or other directories whithin a directory\n"
<<
"mkdir: Create a new directory whithin current directory
\n
"
<<
"mkdir: Create a new directory whithin current directory
\n
"
<<
"noemi: Draw a heart shape made of # characters
\n
"
<<
"noemi: Draw a heart shape made of # characters
\n
"
<<
"noemi -l: Draw a heart shape made of # characters with more delay
\n
"
<<
"noemi -l: Draw a heart shape made of # characters with more delay
\n
"
<<
"now: Gets and prints out the curent date and time
\n
"
<<
"now: Gets and prints out the curent date and time
\n
"
<<
"rn: rename a file or a directory
\n
"
//
<< "rn: rename a file or a directory\n"
<<
"store: Save a string of maximum 100 characters during runtime
\n
"
<<
"store: Save a string of maximum 100 characters during runtime
\n
"
<<
"store -g: Show the string saved with store
\n\n
"
;
<<
"store -g: Show the string saved with store
\n\n
"
;
}
}
...
@@ -308,7 +323,7 @@ bool is_builtin_command(const vector<string>& args){
...
@@ -308,7 +323,7 @@ bool is_builtin_command(const vector<string>& args){
}
}
if
(
args
[
0
]
==
"cd"
){
if
(
args
[
0
]
==
"cd"
){
//
handle_cd(args);
handle_cd
(
args
);
return
true
;
return
true
;
}
}
...
@@ -465,45 +480,51 @@ void handle_list(const vector<string>& args){
...
@@ -465,45 +480,51 @@ void handle_list(const vector<string>& args){
* @param args for arguments.
* @param args for arguments.
*/
*/
/*
void
handle_cd
(
const
vector
<
string
>&
args
)
{
void
handle_cd
(
const
vector
<
string
>&
args
)
{
if
(
args
.
size
()
>
2
)
{
if
(
args
.
size
()
>
2
)
{
cout
<<
"cd: too many arguments
\n
"
;
cout
<<
"cd: too many arguments
\n
"
;
return;
// Exit early
return
;
}
}
if
(
args
.
size
()
==
1
)
{
if
(
args
.
size
()
==
1
)
{
// No argument, go to home directory
// No argument, go to home directory
const char* home_dir = getenv("
USERPROFIL
E");
//
Get home directory on Windows
const
char
*
home_dir
=
getenv
(
"
HOM
E"
);
//
HOME is the Unix/Linux variable
if
(
home_dir
)
{
if
(
home_dir
)
{
fs
::
path
home_path
=
home_dir
;
fs
::
path
home_path
=
home_dir
;
try
{
fs
::
current_path
(
home_path
);
// Change to home directory
fs
::
current_path
(
home_path
);
// Change to home directory
cout << "Changed directory to: " << home_path << endl;
}
catch
(
const
fs
::
filesystem_error
&
e
)
{
cerr
<<
"cd: "
<<
e
.
what
()
<<
endl
;
}
}
else
{
}
else
{
c
out
<< "cd: H
ome directory not found
.\n";
c
err
<<
"cd: H
OME environment variable not set
.
\n
"
;
}
}
}
}
else
if
(
args
[
1
]
==
".."
)
{
else
if
(
args
[
1
]
==
".."
)
{
// cd .., go up one directory level
// cd .., go up one directory level
fs::path current_path = fs::current_path();
try
{
fs::path parent_path = current_path.parent_path(); // Get the parent directory
fs
::
path
parent_path
=
fs
::
current_path
().
parent_path
();
fs::current_path(parent_path); // Change the current path
fs
::
current_path
(
parent_path
);
cout << "Changed directory to: " << parent_path << endl;
}
catch
(
const
fs
::
filesystem_error
&
e
)
{
cerr
<<
"cd: "
<<
e
.
what
()
<<
endl
;
}
}
}
else
{
else
{
// Try to change to the directory specified by the user
// Try to change to the directory specified by the user
fs
::
path
new_path
=
args
[
1
];
fs
::
path
new_path
=
args
[
1
];
try
{
if
(
fs
::
exists
(
new_path
)
&&
fs
::
is_directory
(
new_path
))
{
if
(
fs
::
exists
(
new_path
)
&&
fs
::
is_directory
(
new_path
))
{
fs
::
current_path
(
new_path
);
fs
::
current_path
(
new_path
);
cout << "Changed directory to: " << new_path << endl;
}
else
{
}
else
{
cout
<< "cd: " << new_path << ": No such directory\n";
cerr
<<
"cd: "
<<
new_path
<<
": No such directory
\n
"
;
}
}
}
catch
(
const
fs
::
filesystem_error
&
e
)
{
cerr
<<
"cd: "
<<
e
.
what
()
<<
endl
;
}
}
}
}
*/
}
/**
/**
* Handling the 'read' command for reading text from text based files.
* Handling the 'read' command for reading text from text based files.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment