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
|
||||
- Shell module
|
||||
- strip final newline from load-to-string
|
||||
- cd with no args goes home
|
||||
- cd sets . symbol
|
||||
- ignore job control signals (if needed)
|
||||
- background processes
|
||||
- be able to list all background processes with j function
|
||||
- be able to fg a bg process
|
||||
- be able to bg and fg process (ctrl z?)
|
||||
- changedir/cd
|
||||
- pwd
|
||||
- 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
|
||||
- logging library
|
||||
- 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
|
||||
- store in repo after giving presentation
|
||||
|
||||
** TODO alpha tasks
|
||||
- TYPE SYSTEM HAS NO CTR::NONE
|
||||
- SEG USES Option() AND IF POSSIBLE NO BOX (maybe strings or symbols or numbers are boxed instead?)
|
||||
** TODO v1.0 tasks
|
||||
- export function (dump symbol definitions to script and/or append)
|
||||
- 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
|
||||
- Rename to Flesh
|
||||
- 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
|
||||
- Search delim configurable
|
||||
- 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
|
||||
- get type function
|
||||
- Lex function
|
||||
- Read function (Input + Lex)
|
||||
|
||||
** TODO post-alpha tasks
|
||||
** TODO v1.1 tasks
|
||||
- execute configurable function on cd
|
||||
- Post to relevant channels
|
||||
- Custom ast pretty print
|
||||
- Implement Compose for lambdas
|
||||
Document this in relevant readme sections
|
||||
- Document this in relevant readme sections
|
||||
- File operations
|
||||
- read-to-string
|
||||
- write-to-file
|
||||
- file exists
|
||||
- color control library
|
||||
- emacs syntax highlighting and/or LSP implementation
|
||||
- GNU Guix package
|
||||
|
||||
** TODO Second release tasks
|
||||
** TODO v1.2 release tasks
|
||||
- Network library
|
||||
- HTTP Client
|
||||
- TCP Stream client
|
||||
|
|
@ -572,4 +570,6 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
|
|||
- TCP Listener
|
||||
- HTTP Listener
|
||||
- UDP Listener
|
||||
- emacs syntax highlighting and/or LSP implementation
|
||||
- GNU Guix package
|
||||
- Bindings for the simplest possible UI library
|
||||
|
|
|
|||
|
|
@ -109,3 +109,13 @@ Returns true if the list contains the element.'
|
|||
adds a directory to PATH'
|
||||
(path) (set (q 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 != '.'
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ use std::env::{vars, var, current_dir};
|
|||
use std::rc::Rc;
|
||||
|
||||
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> {
|
||||
|
|
@ -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> {
|
||||
Ok(Ctr::String(">".to_string()))
|
||||
Ok(Ctr::String("λ ".to_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 {
|
||||
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/>.
|
||||
*/
|
||||
|
||||
use crate::segment::{Ctr, Seg};
|
||||
use crate::sym::{SymTable, ValueType, Symbol, Args};
|
||||
use crate::eval::eval;
|
||||
use crate::run;
|
||||
use std::collections::VecDeque;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::fs::File;
|
||||
use std::process::{Command, Child, Stdio};
|
||||
use nix::unistd;
|
||||
use ctrlc;
|
||||
use std::fs::OpenOptions;
|
||||
use {
|
||||
crate::{
|
||||
segment::{Ctr, Seg},
|
||||
sym::{
|
||||
SymTable, ValueType,
|
||||
Symbol, Args,
|
||||
},
|
||||
eval::eval,
|
||||
run,
|
||||
},
|
||||
|
||||
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 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()) == (),
|
||||
}
|
||||
} else {
|
||||
eprintln!("couldnt eval args!") != ()
|
||||
eprintln!("couldnt eval args: {}",
|
||||
eval_res.err().unwrap()) != ()
|
||||
}
|
||||
},
|
||||
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()) == (),
|
||||
}
|
||||
} else {
|
||||
eprintln!("couldnt eval args!") != ()
|
||||
eprintln!("couldnt eval args: {}",
|
||||
eval_res.err().unwrap()) != ()
|
||||
}
|
||||
},
|
||||
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!()
|
||||
}
|
||||
|
||||
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>>) {
|
||||
let pid = unistd::getpid();
|
||||
let pgid_res = unistd::getpgid(Some(pid));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue