cd function
Signed-off-by: Ava Hahn <ava@sunnypup.io>
This commit is contained in:
parent
db55c54dd3
commit
ee1ef9700d
6 changed files with 87 additions and 33 deletions
30
Readme.org
30
Readme.org
|
|
@ -483,16 +483,15 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
|
||||||
|
|
||||||
** TODO Pre-alpha tasks
|
** TODO Pre-alpha tasks
|
||||||
- Shell module
|
- Shell module
|
||||||
|
- strip final newline from load-to-string
|
||||||
|
- cd with no args goes home
|
||||||
|
- cd sets . symbol
|
||||||
- ignore job control signals (if needed)
|
- ignore job control signals (if needed)
|
||||||
- background processes
|
- background processes
|
||||||
- be able to list all background processes with j function
|
- be able to list all background processes with j function
|
||||||
- be able to fg a bg process
|
- be able to fg a bg process
|
||||||
- be able to bg and fg process (ctrl z?)
|
- be able to bg and fg process (ctrl z?)
|
||||||
- changedir/cd
|
|
||||||
- pwd
|
|
||||||
- Documentation!
|
- Documentation!
|
||||||
- Do I need some linemode management stuff?
|
|
||||||
- Function stubs for all posix functions go into minimal shell (posix stub functions)
|
|
||||||
- Escape sequences in strings
|
- Escape sequences in strings
|
||||||
- logging library
|
- logging library
|
||||||
- make const all the error messages
|
- make const all the error messages
|
||||||
|
|
@ -534,9 +533,12 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
|
||||||
- give a pretty pastel white, pink and blue theme
|
- give a pretty pastel white, pink and blue theme
|
||||||
- store in repo after giving presentation
|
- store in repo after giving presentation
|
||||||
|
|
||||||
** TODO alpha tasks
|
** TODO v1.0 tasks
|
||||||
- TYPE SYSTEM HAS NO CTR::NONE
|
- export function (dump symbol definitions to script and/or append)
|
||||||
- SEG USES Option() AND IF POSSIBLE NO BOX (maybe strings or symbols or numbers are boxed instead?)
|
- then write doc on interactive development
|
||||||
|
- completion:
|
||||||
|
- complete string: path search
|
||||||
|
- complete symbol: syms search
|
||||||
- Write next_has member function for &Seg and simplify stdlib and probably also eval/sym
|
- Write next_has member function for &Seg and simplify stdlib and probably also eval/sym
|
||||||
- Rename to Flesh
|
- Rename to Flesh
|
||||||
- Can pass args to relish scripts (via interpreter)
|
- Can pass args to relish scripts (via interpreter)
|
||||||
|
|
@ -544,27 +546,23 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
|
||||||
- History length configurable
|
- History length configurable
|
||||||
- Search delim configurable
|
- Search delim configurable
|
||||||
- master branch -> main branch
|
- master branch -> main branch
|
||||||
- squash top of main and keep pre-alpha history in a historical branch
|
|
||||||
- delete snippets/legacy too
|
|
||||||
- Create a dedicated community channel on matrix.sunnypup.io
|
- Create a dedicated community channel on matrix.sunnypup.io
|
||||||
- get type function
|
|
||||||
- Lex function
|
- Lex function
|
||||||
- Read function (Input + Lex)
|
- Read function (Input + Lex)
|
||||||
|
|
||||||
** TODO post-alpha tasks
|
** TODO v1.1 tasks
|
||||||
|
- execute configurable function on cd
|
||||||
- Post to relevant channels
|
- Post to relevant channels
|
||||||
- Custom ast pretty print
|
- Custom ast pretty print
|
||||||
- Implement Compose for lambdas
|
- Implement Compose for lambdas
|
||||||
Document this in relevant readme sections
|
- Document this in relevant readme sections
|
||||||
- File operations
|
- File operations
|
||||||
- read-to-string
|
- read-to-string
|
||||||
- write-to-file
|
- write-to-file
|
||||||
- file exists
|
- file exists
|
||||||
- color control library
|
- color control library
|
||||||
- emacs syntax highlighting and/or LSP implementation
|
|
||||||
- GNU Guix package
|
|
||||||
|
|
||||||
** TODO Second release tasks
|
** TODO v1.2 release tasks
|
||||||
- Network library
|
- Network library
|
||||||
- HTTP Client
|
- HTTP Client
|
||||||
- TCP Stream client
|
- TCP Stream client
|
||||||
|
|
@ -572,4 +570,6 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
|
||||||
- TCP Listener
|
- TCP Listener
|
||||||
- HTTP Listener
|
- HTTP Listener
|
||||||
- UDP Listener
|
- UDP Listener
|
||||||
|
- emacs syntax highlighting and/or LSP implementation
|
||||||
|
- GNU Guix package
|
||||||
- Bindings for the simplest possible UI library
|
- Bindings for the simplest possible UI library
|
||||||
|
|
|
||||||
|
|
@ -109,3 +109,13 @@ Returns true if the list contains the element.'
|
||||||
adds a directory to PATH'
|
adds a directory to PATH'
|
||||||
(path) (set (q PATH)
|
(path) (set (q PATH)
|
||||||
(concat PATH ':' path)))
|
(concat PATH ':' path)))
|
||||||
|
|
||||||
|
(def display-paths
|
||||||
|
'prints out each element of $PATH one by one'
|
||||||
|
()
|
||||||
|
(let ((path-iter (pop (get-paths))))
|
||||||
|
(while (gt? (len path-iter) 1)
|
||||||
|
(let ((pat (car path-iter))
|
||||||
|
(rem (cdr path-iter)))
|
||||||
|
(echo pat)
|
||||||
|
(set (q path-iter) (pop rem))))))
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,8 @@ fn tok_is_symbol(token: &str) -> Option<String> {
|
||||||
t != '?' &&
|
t != '?' &&
|
||||||
t != '=' &&
|
t != '=' &&
|
||||||
t != '.' &&
|
t != '.' &&
|
||||||
t != '/'
|
t != '/' &&
|
||||||
|
t != '.'
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ use std::env::{vars, var, current_dir};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
fn l_prompt_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, String> {
|
fn l_prompt_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, String> {
|
||||||
Ok(Ctr::String("λ".to_string()))
|
Ok(Ctr::String(">".to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn r_prompt_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, String> {
|
fn r_prompt_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, String> {
|
||||||
|
|
@ -34,7 +34,7 @@ fn r_prompt_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prompt_delimiter_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, String> {
|
fn prompt_delimiter_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, String> {
|
||||||
Ok(Ctr::String(">".to_string()))
|
Ok(Ctr::String("λ ".to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_paths() -> Vec<String> {
|
fn get_paths() -> Vec<String> {
|
||||||
|
|
|
||||||
11
src/stl.rs
11
src/stl.rs
|
|
@ -648,6 +648,17 @@ pub fn dynamic_stdlib(syms: &mut SymTable, shell: Option<Rc<RefCell<posix::Shell
|
||||||
|
|
||||||
if posix_cfg_user_form {
|
if posix_cfg_user_form {
|
||||||
posix::load_posix_shell(syms, shell_state);
|
posix::load_posix_shell(syms, shell_state);
|
||||||
|
syms.insert(
|
||||||
|
"cd".to_string(),
|
||||||
|
Symbol {
|
||||||
|
name: String::from("cd"),
|
||||||
|
args: Args::Strict(vec![Type::String]),
|
||||||
|
conditional_branches: false,
|
||||||
|
docs: posix::CD_DOCSTRING.to_string(),
|
||||||
|
value: ValueType::Internal(Rc::new(posix::cd_callback)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,18 +15,33 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::segment::{Ctr, Seg};
|
use {
|
||||||
use crate::sym::{SymTable, ValueType, Symbol, Args};
|
crate::{
|
||||||
use crate::eval::eval;
|
segment::{Ctr, Seg},
|
||||||
use crate::run;
|
sym::{
|
||||||
use std::collections::VecDeque;
|
SymTable, ValueType,
|
||||||
use std::cell::RefCell;
|
Symbol, Args,
|
||||||
use std::rc::Rc;
|
},
|
||||||
use std::fs::File;
|
eval::eval,
|
||||||
use std::process::{Command, Child, Stdio};
|
run,
|
||||||
use nix::unistd;
|
},
|
||||||
use ctrlc;
|
|
||||||
use std::fs::OpenOptions;
|
std::{
|
||||||
|
collections::VecDeque,
|
||||||
|
cell::RefCell,
|
||||||
|
rc::Rc,
|
||||||
|
fs::{File, OpenOptions},
|
||||||
|
path::Path,
|
||||||
|
process::{
|
||||||
|
Command, Child,
|
||||||
|
Stdio,
|
||||||
|
},
|
||||||
|
env::set_current_dir,
|
||||||
|
},
|
||||||
|
|
||||||
|
nix::unistd,
|
||||||
|
ctrlc,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct ShellState {
|
pub struct ShellState {
|
||||||
pub parent_pid: unistd::Pid,
|
pub parent_pid: unistd::Pid,
|
||||||
|
|
@ -54,7 +69,8 @@ pub fn args_from_ast(ast: &Seg, syms: &mut SymTable) -> Vec<String> {
|
||||||
_ => args.push(res_ctr.to_string()) == (),
|
_ => args.push(res_ctr.to_string()) == (),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("couldnt eval args!") != ()
|
eprintln!("couldnt eval args: {}",
|
||||||
|
eval_res.err().unwrap()) != ()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ctr::Seg(ref form) => {
|
Ctr::Seg(ref form) => {
|
||||||
|
|
@ -67,7 +83,8 @@ pub fn args_from_ast(ast: &Seg, syms: &mut SymTable) -> Vec<String> {
|
||||||
_ => args.push(res_ctr.to_string()) == (),
|
_ => args.push(res_ctr.to_string()) == (),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("couldnt eval args!") != ()
|
eprintln!("couldnt eval args: {}",
|
||||||
|
eval_res.err().unwrap()) != ()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ctr::Lambda(_) => eprintln!("lambda passed as shell parameter") != (),
|
Ctr::Lambda(_) => eprintln!("lambda passed as shell parameter") != (),
|
||||||
|
|
@ -443,6 +460,21 @@ fn bg_callback(_ast: &Seg, _syms: &mut SymTable, _state: &mut ShellState) -> Res
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const CD_DOCSTRING: &str =
|
||||||
|
"Expects 1 argument (a string). Changes to a new directory";
|
||||||
|
pub fn cd_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
|
||||||
|
if let Ctr::String(ref dir) = *ast.car {
|
||||||
|
let dirp = Path::new(dir);
|
||||||
|
if let Err(s) = set_current_dir(&dirp) {
|
||||||
|
Err(format!("{}", s))
|
||||||
|
} else {
|
||||||
|
Ok(Ctr::None)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(format!("impossible err: arg not a string"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc<RefCell<ShellState>>) {
|
pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc<RefCell<ShellState>>) {
|
||||||
let pid = unistd::getpid();
|
let pid = unistd::getpid();
|
||||||
let pgid_res = unistd::getpgid(Some(pid));
|
let pgid_res = unistd::getpgid(Some(pid));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue