ShellSage Tools


source

rgrep

 rgrep (term:str, path:str='.', grep_args:str='')

Perform recursive grep search for term in path with optional grep arguments

print(rgrep('navbar', '.', '--context 1'))
/Users/nathan/git/shell_sage/nbs/_quarto.yml-  open-graph: true
/Users/nathan/git/shell_sage/nbs/_quarto.yml-  repo-actions: [issue]
/Users/nathan/git/shell_sage/nbs/_quarto.yml:  navbar:
/Users/nathan/git/shell_sage/nbs/_quarto.yml-    background: primary
/Users/nathan/git/shell_sage/nbs/_quarto.yml-    search: true
--
/Users/nathan/git/shell_sage/nbs/02_tools.ipynb-   "outputs": [],
/Users/nathan/git/shell_sage/nbs/02_tools.ipynb-   "source": [
/Users/nathan/git/shell_sage/nbs/02_tools.ipynb:    "# print(rgrep('navbar', '.', '--context 1'))"
/Users/nathan/git/shell_sage/nbs/02_tools.ipynb-   ]
/Users/nathan/git/shell_sage/nbs/02_tools.ipynb-  },

source

view

 view (path:str, rng:tuple[int,int]=None, nums:bool=False)

View directory or file contents with optional line range and numbers

print(view('.'))
Directory contents of /Users/nathan/git/shell_sage/nbs:
/Users/nathan/git/shell_sage/nbs/00_core.ipynb
/Users/nathan/git/shell_sage/nbs/_quarto.yml
/Users/nathan/git/shell_sage/nbs/02_tools.ipynb
/Users/nathan/git/shell_sage/nbs/styles.css
/Users/nathan/git/shell_sage/nbs/CNAME
/Users/nathan/git/shell_sage/nbs/01_config.ipynb
/Users/nathan/git/shell_sage/nbs/nbdev.yml
/Users/nathan/git/shell_sage/nbs/index.ipynb
/Users/nathan/git/shell_sage/nbs/tmp.conf
/Users/nathan/git/shell_sage/nbs/.ipynb_checkpoints/01_config-checkpoint.ipynb
/Users/nathan/git/shell_sage/nbs/.ipynb_checkpoints/index-checkpoint.ipynb
/Users/nathan/git/shell_sage/nbs/.ipynb_checkpoints/00_core-checkpoint.ipynb
print(view('_quarto.yml', (1,10), nums=True))
     1 │ project:
     2 │   type: website
     3 │ 
     4 │ format:
     5 │   html:
     6 │     theme: cosmo
     7 │     css: styles.css
     8 │     toc: true
     9 │     keep-md: true
    10 │   commonmark: default

source

create

 create (path:str, file_text:str, overwrite:bool=False)

Creates a new file with the given content at the specified path

print(create('test.txt', 'Hello, world!'))
print(view('test.txt', nums=True))
Created file test.txt containing:
Hello, world!
     1 │ Hello, world!

source

insert

 insert (path:str, insert_line:int, new_str:str)

Insert new_str at specified line number

insert('test.txt', 0, 'Let\'s add a new line')
print(view('test.txt', nums=True))
     1 │ Let's add a new line
     2 │ Hello, world!

source

str_replace

 str_replace (path:str, old_str:str, new_str:str)

Replace first occurrence of old_str with new_str in file

str_replace('test.txt', 'new line', '<we replaced this part!>')
print(view('test.txt', nums=True))
     1 │ Let's add a <we replaced this part!>
     2 │ Hello, world!