|
83 | 83 | - `quit --output-selected-files`: if `--output-file` argument is set, output the selected files to it |
84 | 84 | - exit code 102 |
85 | 85 |
|
86 | | -The following is a bash snippet on how to integrate with `quit` |
87 | | - |
88 | | -```bash |
89 | | -function joshuto() { |
90 | | - ID="$$" |
91 | | - mkdir -p /tmp/$USER |
92 | | - OUTPUT_FILE="/tmp/$USER/joshuto-cwd-$ID" |
93 | | - env joshuto --output-file "$OUTPUT_FILE" $@ |
94 | | - exit_code=$? |
95 | | - |
96 | | - case "$exit_code" in |
97 | | - # regular exit |
98 | | - 0) |
99 | | - ;; |
100 | | - # output contains current directory |
101 | | - 101) |
102 | | - JOSHUTO_CWD=$(cat "$OUTPUT_FILE") |
103 | | - cd "$JOSHUTO_CWD" |
104 | | - ;; |
105 | | - # output selected files |
106 | | - 102) |
107 | | - ;; |
108 | | - *) |
109 | | - echo "Exit code: $exit_code" |
110 | | - ;; |
111 | | - esac |
| 86 | +To exit into the current directory you need to add a snippet to your preferred shell's init script to integrate with `quit`. |
| 87 | + |
| 88 | +<details open> |
| 89 | +<summary>POSIX-compliant shells (bash, zsh, dash, ...)</summary> |
| 90 | + |
| 91 | +```shell |
| 92 | +joshuto() { |
| 93 | + ID="$$" |
| 94 | + mkdir -p "/tmp/$USER" |
| 95 | + OUTPUT_FILE="/tmp/$USER/joshuto-cwd-$ID" |
| 96 | + env joshuto --output-file "$OUTPUT_FILE" "$@" |
| 97 | + exit_code="$?" |
| 98 | + |
| 99 | + case "$exit_code" in |
| 100 | + # regular exit |
| 101 | + 0) |
| 102 | + ;; |
| 103 | + # output contains current directory |
| 104 | + 101) |
| 105 | + JOSHUTO_CWD=$(cat "$OUTPUT_FILE") |
| 106 | + cd "$JOSHUTO_CWD" || return |
| 107 | + ;; |
| 108 | + # output selected files |
| 109 | + 102) |
| 110 | + ;; |
| 111 | + *) |
| 112 | + echo "Exit code: $exit_code" |
| 113 | + ;; |
| 114 | + esac |
112 | 115 | } |
113 | 116 | ``` |
| 117 | +</details> |
| 118 | + |
| 119 | +<details> |
| 120 | +<summary>Fish</summary> |
| 121 | + |
| 122 | +```fish |
| 123 | +function joshuto |
| 124 | + set ID %self |
| 125 | + set -l output_file /tmp/$USER/joshuto-cwd-$ID |
| 126 | +
|
| 127 | + mkdir -p /tmp/$USER |
| 128 | + env joshuto --output-file "$output_file" $argv |
| 129 | + set exit_code $status |
| 130 | +
|
| 131 | + switch $exit_code |
| 132 | + case 0 |
| 133 | + # Regular exit, do nothing |
| 134 | + case 101 |
| 135 | + set JOSHUTO_CWD (cat "$output_file") |
| 136 | + cd "$JOSHUTO_CWD" || return |
| 137 | + case 102 |
| 138 | + # Output selected files, no action |
| 139 | + case '*' |
| 140 | + echo "Exit code: $exit_code" |
| 141 | + end |
| 142 | +end |
| 143 | +``` |
| 144 | +</details> |
114 | 145 |
|
115 | 146 | ### `:`: opens the command prompt |
116 | 147 |
|
|
0 commit comments