|
223 | 223 | # utility function to find directories |
224 | 224 | find_dirs() { |
225 | 225 | # list TMUX sessions |
| 226 | + tmux_list=() |
226 | 227 | if [[ -n "${TMUX}" ]]; then |
227 | 228 | current_session=$(tmux display-message -p '#S') |
228 | | - tmux list-sessions -F "[TMUX] #{session_name}" 2>/dev/null | grep -vFx "[TMUX] $current_session" |
| 229 | + while IFS= read -r session; do |
| 230 | + [[ "$session" != "[TMUX] $current_session" ]] && tmux_list+=("$session") |
| 231 | + done < <(tmux list-sessions -F "[TMUX] #{session_name}" 2>/dev/null) |
229 | 232 | else |
230 | | - tmux list-sessions -F "[TMUX] #{session_name}" 2>/dev/null |
| 233 | + while IFS= read -r session; do |
| 234 | + tmux_list+=("$session") |
| 235 | + done < <(tmux list-sessions -F "[TMUX] #{session_name}" 2>/dev/null) |
231 | 236 | fi |
232 | 237 |
|
233 | 238 | # note: TS_SEARCH_PATHS is an array of paths to search for directories |
234 | 239 | # if the path ends with :number, it will search for directories with a max depth of number ;) |
235 | 240 | # if there is no number, it will search for directories with a max depth defined by TS_MAX_DEPTH or 1 if not set |
| 241 | + dir_list=() |
236 | 242 | for entry in "${TS_SEARCH_PATHS[@]}"; do |
237 | 243 | # Check if entry as :number as suffix then adapt the maxdepth parameter |
238 | 244 | if [[ "$entry" =~ ^([^:]+):([0-9]+)$ ]]; then |
239 | 245 | path="${BASH_REMATCH[1]}" |
240 | 246 | depth="${BASH_REMATCH[2]}" |
241 | 247 | else |
242 | 248 | path="$entry" |
| 249 | + depth="${TS_MAX_DEPTH:-1}" |
243 | 250 | fi |
244 | 251 |
|
245 | | - [[ -d "$path" ]] && find "$path" -mindepth 1 -maxdepth "${depth:-${TS_MAX_DEPTH:-1}}" -path '*/.git' -prune -o -type d -print |
| 252 | + if [[ -d "$path" ]]; then |
| 253 | + while IFS= read -r dir; do |
| 254 | + dir_list+=("$dir") |
| 255 | + done < <(find "$path" -mindepth 1 -maxdepth "$depth" -path '*/.git' -prune -o -type d -print) |
| 256 | + fi |
246 | 257 | done |
| 258 | + |
| 259 | + printf '%s\n' "${tmux_list[@]}" |
| 260 | + printf '%s\n' "${dir_list[@]}" | sort |
247 | 261 | } |
248 | 262 |
|
249 | 263 | handle_session_cmd() { |
|
0 commit comments