mirror of
				https://github.com/mitchell/swim.fish.git
				synced 2025-11-03 23: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
 | 
			
		||||
 | 
			
		||||
function main
 | 
			
		||||
    alias $run_func_prefix\_default=$run_func_prefix\_help
 | 
			
		||||
    define_aliases
 | 
			
		||||
 | 
			
		||||
    for command in $argv
 | 
			
		||||
        set -l last_status $status
 | 
			
		||||
        test $last_status -gt 0; and exit $last_status
 | 
			
		||||
 | 
			
		||||
        execute_command $run_func_prefix $command
 | 
			
		||||
        and execute_command $run_func_prefix $command
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if test -z "$argv"
 | 
			
		||||
        execute_command $run_func_prefix default
 | 
			
		||||
    and if test -z "$argv"
 | 
			
		||||
        execute_command $run_func_prefix
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -31,10 +25,10 @@ function execute_command -a prefix command
 | 
			
		|||
 | 
			
		||||
    define_default_functions $prefix
 | 
			
		||||
 | 
			
		||||
    if functions -q $func
 | 
			
		||||
        $func $args[2]
 | 
			
		||||
    else if test -z "$command"
 | 
			
		||||
    if test -z "$command"
 | 
			
		||||
        execute_command $prefix default
 | 
			
		||||
    else if functions -q $func
 | 
			
		||||
        $func $args[2]
 | 
			
		||||
    else
 | 
			
		||||
        echo "$prefix command '$command' does not exist"
 | 
			
		||||
        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`"
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if not functions -q $prefix\_default
 | 
			
		||||
        function $prefix\_default -a arg -d 'Alias for help command'
 | 
			
		||||
            $prefix\_help $arg
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
main $argv
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										28
									
								
								run.fish
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								run.fish
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -3,25 +3,21 @@
 | 
			
		|||
# Source: https://github.com/mitchell/run.fish
 | 
			
		||||
 | 
			
		||||
### 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 ':'
 | 
			
		||||
 | 
			
		||||
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 ###
 | 
			
		||||
# Add, edit, and remove commands freely below.
 | 
			
		||||
# 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'
 | 
			
		||||
    if test -z "$bin_path"
 | 
			
		||||
        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
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function run_fails -d 'This command fails every time'
 | 
			
		||||
    false
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue