Warning: Work in progress! Leave feedback on Zulip or Github if you'd like this doc to be updated.

YSH Types and Methods

This chapter in the Oils Reference describes YSH types and methods.

Table of Contents
Null
Bool
Int
Float
Str
find()
replace()
startsWith()
endsWith()
trim()
trimLeft()
trimRight()
trimPrefix()
trimSuffix()
upper()
lower()
List
append()
pop()
extend()
find()
insert()
remove()
reverse()
Dict
keys()
values()
get()
erase()
inc()
accum()
Place
setValue()
IO
eval()
captureStdout()
promptVal()
time()
strftime()
glob()

Null

Bool

Int

Float

Str

find()

replace()

startsWith()

endsWith()

trim()

Respects unicode space.

trimLeft()

Respects unicode space.

trimRight()

Respects unicode space.

trimPrefix()

trimSuffix()

upper()

Respects unicode.

lower()

Respects unicode.

List

append()

pop()

extend()

find()

insert()

remove()

reverse()

Dict

keys()

values()

get()

erase()

inc()

accum()

Place

setValue()

A Place is used as an "out param" by calling setValue():

proc p (out) {
  call out->setValue('hi')
}

var x
p (&x)
echo x=$x  # => x=hi

IO

eval()

Like the eval builtin, but useful in pure functions.

captureStdout()

Like $(), but useful in pure functions.

promptVal()

An API the wraps the $PS1 language. For example, to simulate PS1='\w\$ ':

func renderPrompt(io) {    
  var parts = []
  call parts->append(io->promptval('w'))  # pass 'w' for \w
  call parts->append(io->promptval('$'))  # pass '$' for \$
  call parts->append(' ')
  return (join(parts))
}

time()

TODO: Depends on system clock.

strftime()

TODO: Like the awk function, this takes an timestamp directly.

In other words, it calls C localtime() (which depends on the time zone database), and then C strftime().

glob()

TODO: The free function glob() actually does I/O. Although maybe it doesn't fail?


Generated on Wed, 06 Dec 2023 01:04:01 -0500