j178 / leetgo

Best LeetCode friend for geek. :snowboarder:
MIT License
540 stars 32 forks source link

feat: open different files using different editors #152

Closed w43322 closed 1 year ago

w43322 commented 1 year ago

Users might want to use different programs to edit / view different file, e.g. it might not be very helpful to open a .md file with vim

j178 commented 1 year ago

I thought this might introduce some complicated editor related configurations, so I will take another approach.

After #168, it is possible to achieve this with a helper script.

like this:

editor:
  command: /usr/local/bin/opener.sh
  args: ['{{.AllFiles}}' ]

/usr/local/bin/opener.sh (not tested, may not work):

#!/bin/bash

if [ $# -gt 0 ]; then
    for filepath in "$@"
    do
        file_extension="${filepath##*.}"
        case "$file_extension" in
            md)
                code "$filepath" &
                ;;
            *)
                vim -n "$filepath" &
                ;;
        esac
    done
else
    echo "No file paths provided"
    exit 1
fi
w43322 commented 1 year ago

that works