image/svg+xml R reload thisdirectory r :open_with ^R resetranger E edit e W show log w show back-ground tasks Q quit q
def random generator:&:stream:num -> result:num, fail?:bool, generator:&:stream:num [
  local-scope
  load-inputs
  {
    break-if generator
    # generator is 0? use real random-number generator
    result <- real-random
    return result, false
  }
  result, fail?, generator <- read generator
]

# helper for tests
def assume-random-numbers -> result:&:stream:num [
  local-scope
  load-inputs
  # compute result-len, space to allocate in result
  result-len:num <- copy 0
  {
    _, arg-received?:bool <- next-input
    break-unless arg-received?
    result-len <- add result-len, 1
    loop
  }
  rewind-inputs
  result-data:&:@:num <- new number:type, result-len
  idx:num <- copy 0
  {
    curr:num, arg-received?:bool <- next-input
    break-unless arg-received?
    *result-data <- put-index *result-data, idx, curr
    idx <- add idx, 1
    loop
  }
  result <- new-stream result-data
]

scenario random-numbers-in-scenario [
  local-scope
  source:&:stream:num <- assume-random-numbers 34, 35, 37
  1:num/raw, 2:bool/raw <- random source
  3:num/raw, 4:bool/raw <- random source
  5:num/raw, 6:bool/raw <- random source
  7:num/raw, 8:bool/raw <- random source
  memory-should-contain [
    1 <- 34
    2 <- 0  # everything went well
    3 <- 35
    4 <- 0  # everything went well
    5 <- 37
    6 <- 0  # everything went well
    7 <- 0  # empty result
    8 <- 1  # end of stream
  ]
]

# generate a random integer in the semi-open interval [start, end)
def random-in-range generator:&:stream:num, start:num, end:num -> result:num, fail?:bool, generator:&:stream:num [
  local-scope
  load-inputs
  result, fail?, generator <- random generator
  return-if fail?
  delta:num <- subtract end, start
  _, result <- divide-with-remainder result, delta
  result <- add result, start
]

scenario random-in-range [
  local-scope
  source:&:stream:num <- assume-random-numbers 91
  1:num/raw <- random-in-range source, 40, 50
  memory-should-contain [
    1 <- 41
  ]
]
175.5" height="18.999977" width="79" id="rect4230-1-8-4-2-4" style="fill:#ffcc00;fill-opacity:1;stroke:#000000;stroke-width:0.99999994;stroke-opacity:1" /> I i inspect file :rename(insert) O o sort P p paste (3) { [ move up inparent dir } traverse sub-directories ] move downin parent dir @ :shell %s 2 (1) # :shell -p 3 (1) $ 4 (1) % 5 (1) ^ 6 (1) & 7 (1) * 8 (1) ( 9 (1) ) 0 (1) _ - chmod (2) + chmod (2) = chmod (2) A :rename(append) a :rename (skipextension) S open shell s :shell D d cut (3) (4) move downhalf page ^D F f :find ^F move down1 page G go to top g :cd ... H back inhistory h go up 1directory ^H togglehidden files J move downhalf page j move down K move uphalf page k move up L forward inhistory l enter dir/open file ^L redraw : console ; console ' openbookmarks " tag files withcustom tag CAPSLOCK SHIFT Z ZZ/ZQ = quit z toggleoptions X x ^C C c select files incertain order abort task V visual mode v invertselection B b ^B move up1 page N searchprevious n search next ^N new tab M change (5)linemode m savebookmark < , > . ? show help / :search F1 help F3 inspect file F4 edit F5 copy F6 cut F7 :mkdir F8 :delete F10 quit F2 F9 F11 F12 ranger cheatsheet http://ranger.nongnu.org git clone https://github.com/hut/ranger Macros can be used in commands. They are likeglobal variables with dynamic content: %f%d%s%t%c%any%rangerdir%space The base name of the current fileThe path of the current directoryThe names of the currently selected filesThe names of all tagged files in this directoryThe paths of the currently copied filesThe key used in a key binding with "<any>"Example: map x<any> shell -w echo %anyThe path to the ranger python moduleJust a space, to avoid typing trailing spaces Example: map yp shell echo %d/%f | xsel -iThey can be escaped by replacing % with %%. (1) numbers can be used as a quantifier in various commands, for example 5j will movethe cursor down 5 by lines, 3<space> selects 3 files, 4<TAB> moves you to the 4th tab.(2) the keys -, + and = change the permissions of files. See "man chmod". [+-][augo][rwxXst] (e.g. +gw means "add write permissions to the group) [+-][rwxXst] (e.g. -x means "remove execute permissions from everybody") <octal>= (e.g. 777= means "give full permissions to everybody")(3) yank, copy, paste: To copy files, select them with the cursor (or <space>, in case ofmultiple files) → type dd (to cut) or yy (to copy) → move to the destination → type pp.Type da (or ya) to add files to the copy buffer, allowing you to copy from multiple folders.(4) d also starts the keybindings dc (calculate size of the content of a directory), du/dU(calculate directory size with the "du" program), dD (open the console with ":delete")(5) M<key> changes the linemode - the way files are drawn. Mf draws just the file name,Mp draws permissions, Mi draws file type information, Mt draws metadata, as definedwith the :meta command. You can add custom linemodes as described in/usr/share/doc/ranger/examples/plugin_linemode.py Config files: run "ranger --copy-config=all" tocopy the default config files to ~/.config/ranger/. rc.conf: A list of commands that are executed when rangerstarts. Options, key bindings and aliases are found here.Pro tip: Adding "export RANGER_LOAD_DEFAULT_RC=FALSE" toyour shell rc will skip loading the default rc.conf before your own.commands.py: A python script containing custom commandsrifle.conf: Rules for rifle, the file opener. Each line looks like list of conditions = commandWhen ranger opens a file, it tests those conditions. The firstcommand where all conditions are true will be executed.scope.sh: The script that generates file previews.Plugins can be put in the plugins/ subdirectory, colorschemesin colorschemes/. See /usr/share/doc/ranger/examples. #ranger on irc.freenode.net Commands can be typed in by pressing : or added to ~/.config/ranger/rc.conf to apply then wheneverranger starts. All commands are listed in the man page. Some important ones: :shell [<flags>] <command> calls the given <command> with the shell specified in the environmentvariable $SHELL. <flags> can be "-f" to fork the process or "-p" to pipe the output to a pager. Macros like%f and %s are especially useful here. Example: ":shell -f inkscape %f" or ":shell sudo cp %c ./":alias <new> <old> creates the command <new> that calls <old>. The neat thing is that you can passarguments to the next command. Example: ":alias touch shell touch" will allow you to type ":touch FILE",which will be translated to ":shell touch FILE".:map <key> <command> makes the <key> run <command> when pressed. This is the typical way todefine key bindings in rc.conf. There is also "pmap" to define keys in the pager and "unmap" and "punmap"to remove key bindings.