Skip to content

Commit 73340ed

Browse files
useful_scripts/sublf.sh: do general improvements
1 parent e0dd7ac commit 73340ed

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

useful_scripts/sublf.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
# This file is part of eRCaGuy_dotfiles: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles
44

5-
# STATUS: WORK-IN-PROGRESS! **NOT** YET READY FOR USE.
5+
# This program allows you to quickly open up any file you want in Sublime Text by selecting files
6+
# with the `fzf` fuzzy finder and then passing them to `subl`. Just run it and you'll see what I
7+
# mean!
8+
9+
# STATUS: WORK-IN-PROGRESS! It works, but it needs some massive cleanup in the comments and I need
10+
# to generally clean up and refactor the code as necessary. It does work though, so feel free
11+
# to use it.
612

713
####### sample alias
814
# see also: https://stackoverflow.com/a/69830768/4561887
@@ -56,11 +62,13 @@
5662
# SEE ALSO MY ANSWER HERE: https://stackoverflow.com/a/70658963/4561887
5763
sublf() {
5864
echo "DEBUG: all args = $@" # FOR DEBUGGING
65+
5966
search_path="."
6067
if [ $# -gt 0 ]; then
6168
search_path="$1"
6269
shift # remove $1 from input args array
6370
fi
71+
6472
all_find_args_array=()
6573
all_find_args_array+=("$search_path")
6674
all_find_args_array+=("$@") # pass through all other args to `find`
@@ -70,6 +78,14 @@ sublf() {
7078
# 2. and my answer here: https://stackoverflow.com/a/69830768/4561887
7179
all_find_args_array+=(-not \( -path "*/.git/*" -prune \))
7280
all_find_args_array+=(-not \( -path "*/..git/*" -prune \))
81+
82+
# Add additional custom user args or excludes
83+
additional_find_args_or_excludes=()
84+
if [ -f ~/.sublf_config.sh ]; then
85+
. ~/.sublf_config.sh
86+
fi
87+
all_find_args_array+=("${additional_find_args_or_excludes[@]}")
88+
7389
echo "DEBUG: all_find_args_array = ${all_find_args_array[@]}" # FOR DEBUGGING
7490

7591
files_selected="$(find "${all_find_args_array[@]}" | fzf -m)"
@@ -88,9 +104,12 @@ sublf() {
88104
files_selected_array=($files_selected) # split long string into array, separating by IFS (newline chars)
89105
IFS=$SAVEIFS # Restore IFS
90106

91-
echo "Opening these files in Sublime Text:"
107+
echo "Opening these files or folders in Sublime Text:"
108+
num_files="${#files_selected_array[@]}"
109+
i=1
92110
for file in "${files_selected_array[@]}"; do
93-
printf " %s\n" "$file"
111+
printf " %2i/%-2i: %s\n" "$i" "$num_files" "$file"
112+
((i++))
94113
done
95114

96115
# See: https://stackoverflow.com/a/70572787/4561887

0 commit comments

Comments
 (0)