Skip to content

Commit

Permalink
update which_ed to which instead of find
Browse files Browse the repository at this point in the history
  • Loading branch information
zpiatt committed Dec 23, 2022
1 parent dad3b85 commit a366feb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Upcoming features:
- Added `-m` option to generate multiple files at once.
- `gen -m 3 test.sh` creates files similarly to `touch test{1..3}.sh`.
- Added which_ed function.
- If `$EDITOR` is unset, `find` now searches `/usr/bin` for several other editors. In practice, this will likely select an editor alphabetically. If the behavior is undesired, please refer to the `Editors` wiki linked below for how-to set your `$EDITOR` environmental variable.
- If `$EDITOR` is unset, `which` now searches `$PATH` for the following editors: `nano, vim, vi, emacs, ed`. If the behavior is undesired, please refer to the `Editors` wiki linked below for how-to set your `$EDITOR` environmental variable.

Please send me any ideas for increasing portability, or adding features!

Expand Down
18 changes: 5 additions & 13 deletions gen
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

version="Generate (gen) version: 1.5.5 - December 18, 2022"
version="Generate (gen) version: 1.5.6 - December 22, 2022"

which_template() {
if [[ -n "${template:-}" ]]; then
Expand Down Expand Up @@ -126,18 +126,10 @@ exit 0
}

which_ed() {
while IFS= read -r file; do
case "$file" in
*/emacs) EDITOR="/usr/bin/emacs"; return ;;
*/mc) EDITOR="/usr/bin/mc"; return ;;
*/micro) EDITOR="/usr/bin/micro"; return ;;
*/nano) EDITOR="/usr/bin/nano"; return ;;
*/ne) EDITOR="/usr/bin/ne"; return ;;
*/nvim) EDITOR="/usr/bin/nvim"; return ;;
*/vim) EDITOR="/usr/bin/vim"; return ;;
*/vi) EDITOR="/usr/bin/vi"; return ;;
esac
done < <(find /usr/bin)
editors=( nano vim vi emacs ed )
for editor in "${editors[@]}"; do
EDITOR="$(which "$editor" 2> /dev/null)" && return
done
}

create_one() {
Expand Down

0 comments on commit a366feb

Please sign in to comment.