mirror of
				https://github.com/mitchell/swim.fish.git
				synced 2025-11-04 07:35:25 +00:00 
			
		
		
		
	Cleanup default command logic and remove define_aliases hook
This commit is contained in:
		
							parent
							
								
									2545c4dd95
								
							
						
					
					
						commit
						e45d11220c
					
				
							
								
								
									
										24
									
								
								run
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								run
									
									
									
									
									
								
							| 
						 | 
					@ -10,18 +10,12 @@ else
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function main
 | 
					function main
 | 
				
			||||||
    alias $run_func_prefix\_default=$run_func_prefix\_help
 | 
					 | 
				
			||||||
    define_aliases
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for command in $argv
 | 
					    for command in $argv
 | 
				
			||||||
        set -l last_status $status
 | 
					        and execute_command $run_func_prefix $command
 | 
				
			||||||
        test $last_status -gt 0; and exit $last_status
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        execute_command $run_func_prefix $command
 | 
					 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if test -z "$argv"
 | 
					    and if test -z "$argv"
 | 
				
			||||||
        execute_command $run_func_prefix default
 | 
					        execute_command $run_func_prefix
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,10 +25,10 @@ function execute_command -a prefix command
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    define_default_functions $prefix
 | 
					    define_default_functions $prefix
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if functions -q $func
 | 
					    if test -z "$command"
 | 
				
			||||||
        $func $args[2]
 | 
					 | 
				
			||||||
    else if test -z "$command"
 | 
					 | 
				
			||||||
        execute_command $prefix default
 | 
					        execute_command $prefix default
 | 
				
			||||||
 | 
					    else if functions -q $func
 | 
				
			||||||
 | 
					        $func $args[2]
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        echo "$prefix command '$command' does not exist"
 | 
					        echo "$prefix command '$command' does not exist"
 | 
				
			||||||
        exit 1
 | 
					        exit 1
 | 
				
			||||||
| 
						 | 
					@ -70,6 +64,12 @@ function define_default_functions
 | 
				
			||||||
            echo "To see a subcommand group's help menu do `run {command}$run_arg_delimeter""help`"
 | 
					            echo "To see a subcommand group's help menu do `run {command}$run_arg_delimeter""help`"
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if not functions -q $prefix\_default
 | 
				
			||||||
 | 
					        function $prefix\_default -a arg -d 'Alias for help command'
 | 
				
			||||||
 | 
					            $prefix\_help $arg
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
main $argv
 | 
					main $argv
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										28
									
								
								run.fish
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								run.fish
									
									
									
									
									
								
							| 
						 | 
					@ -3,25 +3,21 @@
 | 
				
			||||||
# Source: https://github.com/mitchell/run.fish
 | 
					# Source: https://github.com/mitchell/run.fish
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Config ###
 | 
					### Config ###
 | 
				
			||||||
# Top-level configurations, like the argument delimeter and aliases.
 | 
					# Top-level configurations, like the argument delimeter and custom global variables.
 | 
				
			||||||
#
 | 
					
 | 
				
			||||||
set -g run_arg_delimeter ':'
 | 
					set -g run_arg_delimeter ':'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function define_aliases
 | 
					 | 
				
			||||||
    alias run_default='run_help'
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    alias run_i='run_install'
 | 
					 | 
				
			||||||
    alias run_l='run_lint'
 | 
					 | 
				
			||||||
    alias run_f='run_format'
 | 
					 | 
				
			||||||
    alias run_h='run_hello'
 | 
					 | 
				
			||||||
    alias hello_w='hello_world'
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
### Commands ###
 | 
					### Commands ###
 | 
				
			||||||
# Add, edit, and remove commands freely below.
 | 
					# Add, edit, and remove commands freely below.
 | 
				
			||||||
# To add a command simply create a function with this naming scheme: {run_func_prefix}_{name}.
 | 
					# To add a command simply create a function with this naming scheme: {run_func_prefix}_{name}.
 | 
				
			||||||
#
 | 
					
 | 
				
			||||||
 | 
					function run_default -a arg -d 'Display this help menu'
 | 
				
			||||||
 | 
					    # This command will run in when you simply execute `run` in this repo.
 | 
				
			||||||
 | 
					    # The default command is set to help by default.
 | 
				
			||||||
 | 
					    # So you can omit this from your run.fish if you like that behavior.
 | 
				
			||||||
 | 
					    run_help $arg
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function run_install -a bin_path -d 'Install the run script to a bin folder'
 | 
					function run_install -a bin_path -d 'Install the run script to a bin folder'
 | 
				
			||||||
    if test -z "$bin_path"
 | 
					    if test -z "$bin_path"
 | 
				
			||||||
        if test -d ~/.local/bin
 | 
					        if test -d ~/.local/bin
 | 
				
			||||||
| 
						 | 
					@ -60,3 +56,7 @@ function run_hello -a command -d 'This is an example of a subgroup of commands'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    execute_command 'hello' $command # this command comes from the run script
 | 
					    execute_command 'hello' $command # this command comes from the run script
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function run_fails -d 'This command fails every time'
 | 
				
			||||||
 | 
					    false
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue