-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Let users add their own program/configs with a command #117
Comments
I agree and would be happy to help. I believe this would require an external text file to keep track. I have rewritten the function to avoid boilerplate, and make it easier to add your own stuff assuming the config file is in the home directory. # emc - Edit My Config.
# https://github.com/demartini/emc.fish
set -g _emc_version 1.0.0
set -g aliases "bash"\
"fish"\
"git"\
"gpg"\
"gpga"\
'ssh'\
"nvim"\
"starship"\
"tmux"\
"vim"\
"zsh"
set -g files ".bashrc"\
".config/fish/config.fish"\
".gitconfig"\
".gnupg/gpg.conf"\
".gnupg/gpg-agent.conf"\
".ssh/config"\
".config/nvim/init.vim"\
".config/starship.toml"\
".tmux.conf"\
".vimrc"\
".zshrc"
function __emc -d "Edit My Config"
set option $argv[1]
switch "$option"
case 'help'
_emc_help
return
case 'version'
echo -e "$EMC_CMD, version $_emc_version"
return
case ''
_emc_help >&2
return 1
end
# Checks the input mathes alias
set index 1
for alias in $aliases
if test "$alias" = "$option"
_open_file $files[$index]
return
end
set index (math $index + 1)
end
echo -e (set_color red --bold)"✗ Unknown option: $option"(set_color normal) >&2
end
function _open_file
set file $argv[1]
if test -f $HOME/$file
echo -e (set_color cyan)"→ Opening" (set_color --underline)"~/$file"(set_color normal) (set_color cyan)"file."(set_color normal)
command $EMC_EDITOR $HOME/$file
else
echo -e (set_color red --bold)"✗ The" (set_color --underline)"~/$file"(set_color normal) (set_color red --bold)"file does not exist."(set_color normal)
end
end Using this rewritten function instead, it's also easy to just set the aliases, and their paths as empty list, and read from a file. If we have a text file called "options.txt" like this:
We could simply define the aliases and their paths like this: set aliases
set files
set file_content (cat "options.txt")
set lines (string split \n $file_content)
for line in $lines
set l (string split "," $line)
set -a aliases $l[1]
set -a files $l[2]
end With an "add_option" method looking like this: function _add_option
set name $argv[1]
set config_path $argv[2]
if not contains \'$name\' $aliases
echo "Adding '$name','$folder' to options.txt"
echo "'$name'","'$folder'" >> "options.txt"
else
echo "Entry '$name','$folder' already exists in options.txt"
end
end Thoughts? |
[#118 ] |
Hello everyone, sorry for the delay, I've been a bit busy in the past few months. @MrDowntempo I really liked the idea of being able to add more settings without having to rewrite the plugin every time. @Oskar-Idland Thank you so much for your contribution; it will be of great help. I'll test it, review it, and provide feedback soon. |
@MrDowntempo If you want the feature now, you can install my fork instead:
Usage is documented in the README. I have been using it since my pull request |
Very cool! I'll give it a shot a little later this week |
There seems to be a minor issue with either your implementation, or just the instructions. It mentions an emc_config.txt file, but it seems like the file is just emc_config. Not sure if its smarter to add the .txt to match the docs, or change the docs to just emc_config. Alternatively, might be nice as a csv? ¯_(ツ)_/¯ But other than that, it seems to be working as intended. Got my wezterm config file added which I was missing, and am able to edit with an emc. Nice to be able to remove the config files I'm not using as well. |
Whoops, I fixed that now. The |
This is a handy tool, but only for the small handful of programs. It would be much more useful if you could add your own programs to it with a single function or command.
The text was updated successfully, but these errors were encountered: