summary refs log tree commit diff stats
path: root/examples/bash_automatic_cd.sh
blob: 040bf21a3134e5048f84279be68b3039e0c09d8b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Compatible with ranger 1.4.2 through 1.7.*
#
# Automatically change the directory in bash after closing ranger
#
# This is a bash function for .bashrc to automatically change the directory to
# the last visited one after ranger quits.
# To undo the effect of this function, you can type "cd -" to return to the
# original directory.

function ranger-cd {
    tempfile="$(mktemp -t tmp.XXXXXX)"
    /usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}"
    test -f "$tempfile" &&
    if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
        cd -- "$(cat "$tempfile")"
    fi
    rm -f -- "$tempfile"
}

# This binds Ctrl-O to ranger-cd:
bind '"\C-o":"ranger-cd\C-m"'
o "jump_backward") recipe main [ jump 1:offset # 0 -+ jump 1:offset # | +-+ 1 # \/ /\ | jump -2:offset # 2 +-->+ | ] # \/ 3 +run: instruction main/0 +run: instruction main/2 +run: instruction main/1 :(before "End Primitive Recipe Declarations") JUMP_IF, :(before "End Primitive Recipe Numbers") Recipe_number["jump-if"] = JUMP_IF; :(before "End Primitive Recipe Implementations") case JUMP_IF: { vector<int> arg0 = read_memory(instructions[pc].ingredients[0]); assert(arg0.size() == 1); trace("run") << "ingredient 0 is " << arg0[0]; if (!arg0[0]) { trace("run") << "jump-if fell through"; break; } trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; pc += instructions[pc].ingredients[1].value; trace("run") << "jumping to instruction " << pc+1; break; } :(scenario "jump_if") recipe main [ jump-if 999:literal 1:offset 1:integer <- copy 1:literal ] +run: instruction main/0 +run: ingredient 1 is 1 +run: jumping to instruction 2 -run: instruction main/1 -mem: storing 1 in location 1 :(scenario "jump_if_fallthrough") recipe main [ jump-if 0:literal 1:offset 123:integer <- copy 1:literal ] +run: instruction main/0 +run: jump-if fell through +run: instruction main/1 +mem: storing 1 in location 123 :(before "End Primitive Recipe Declarations") JUMP_UNLESS, :(before "End Primitive Recipe Numbers") Recipe_number["jump-unless"] = JUMP_UNLESS; :(before "End Primitive Recipe Implementations") case JUMP_UNLESS: { vector<int> arg0 = read_memory(instructions[pc].ingredients[0]); assert(arg0.size() == 1); trace("run") << "ingredient 0 is " << arg0[0]; if (arg0[0]) { trace("run") << "jump-unless fell through"; break; } trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; pc += instructions[pc].ingredients[1].value; trace("run") << "jumping to instruction " << pc+1; break; } :(scenario "jump_unless") recipe main [ jump-unless 0:literal 1:offset 1:integer <- copy 1:literal ] +run: instruction main/0 +run: ingredient 1 is 1 +run: jumping to instruction 2 -run: instruction main/1 -mem: storing 1 in location 1 :(scenario "jump_unless_fallthrough") recipe main [ jump-unless 999:literal 1:offset 123:integer <- copy 1:literal ] +run: instruction main/0 +run: ingredient 0 is 999 +run: jump-unless fell through +run: instruction main/1 +mem: storing 1 in location 123