mirror of
				https://github.com/mitchell/swim.fish.git
				synced 2025-11-03 23:35:25 +00:00 
			
		
		
		
	Replace default commands with more usefull commands and exmaples
This commit is contained in:
		
							parent
							
								
									479f57997a
								
							
						
					
					
						commit
						2c1a20f125
					
				
							
								
								
									
										15
									
								
								run
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								run
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -1,6 +1,13 @@
 | 
			
		|||
#!/usr/bin/env fish
 | 
			
		||||
 | 
			
		||||
source ./run.fish
 | 
			
		||||
set -g run_func_prefix 'run'
 | 
			
		||||
 | 
			
		||||
if test -f ./run.fish
 | 
			
		||||
    source ./run.fish
 | 
			
		||||
else
 | 
			
		||||
    echo 'No run.fish found in current directory. Please copy the template from https://github.com/mitchell/run.fish'
 | 
			
		||||
    exit 1
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function main
 | 
			
		||||
    define_aliases
 | 
			
		||||
| 
						 | 
				
			
			@ -9,11 +16,11 @@ function main
 | 
			
		|||
        set -l last_status $status
 | 
			
		||||
        test $last_status -gt 0; and exit $last_status
 | 
			
		||||
 | 
			
		||||
        execute_command 'run' $command
 | 
			
		||||
        execute_command $run_func_prefix $command
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if test -z "$argv"
 | 
			
		||||
        execute_command 'run' default
 | 
			
		||||
        execute_command $run_func_prefix default
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -25,6 +32,8 @@ function execute_command -a prefix command
 | 
			
		|||
 | 
			
		||||
    if functions -q $func
 | 
			
		||||
        $func $args[2]
 | 
			
		||||
    else if test -z "$command"
 | 
			
		||||
        execute_command $prefix default
 | 
			
		||||
    else
 | 
			
		||||
        echo "$prefix command '$command' does not exist"
 | 
			
		||||
        exit 1
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										65
									
								
								run.fish
									
									
									
									
									
								
							
							
						
						
									
										65
									
								
								run.fish
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -1,16 +1,14 @@
 | 
			
		|||
# This run.fish script serves as a central place to store frequently run commands for this project.
 | 
			
		||||
# Replace command section with your own command functions.
 | 
			
		||||
# Source: https://github.com/mitchell/run.fish
 | 
			
		||||
 | 
			
		||||
### Config ###
 | 
			
		||||
# Top-level configurations, like function prefixes and argument delimeters
 | 
			
		||||
# Top-level configurations, like the argument delimeter and aliases.
 | 
			
		||||
#
 | 
			
		||||
set -g run_arg_delimeter ':'
 | 
			
		||||
 | 
			
		||||
function define_aliases
 | 
			
		||||
    alias run_h='run_hello'
 | 
			
		||||
    alias run_l='run_lang'
 | 
			
		||||
 | 
			
		||||
    alias lang_f='lang_fr'
 | 
			
		||||
    alias run_default='run_install'
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -18,30 +16,41 @@ end
 | 
			
		|||
# 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 -d 'Say bonjour to run.fish user'
 | 
			
		||||
    run_lang fr:'run.fish user'
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function run_hello -d 'Say hello to the world'
 | 
			
		||||
    echo 'hello, world!'
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function run_hey -a name -d 'Say hey to someone specific'
 | 
			
		||||
    echo "hey, $name!"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function run_lang -a command -d 'Groups lang subcommands'
 | 
			
		||||
    function lang_en -d 'Say hello in english'
 | 
			
		||||
        run_hello
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    function lang_fr -a name -d 'Say hello the world or someone specific, in french'
 | 
			
		||||
        if test -n "$name"
 | 
			
		||||
            echo "bonjour, $name!"
 | 
			
		||||
        else
 | 
			
		||||
            echo 'bonjour, le monde!'
 | 
			
		||||
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
 | 
			
		||||
            set bin_path ~/.local/bin
 | 
			
		||||
        else if test -d /usr/local/bin
 | 
			
		||||
            set bin_path /usr/local/bin
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    execute_command 'lang' $command
 | 
			
		||||
    echo "Installing run script to $bin_path."
 | 
			
		||||
    cp ./run $bin_path/
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function run_lint -d 'Lint fish scripts'
 | 
			
		||||
    fish --no-execute ./run ./run.fish
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function run_format -d 'Format fish scripts'
 | 
			
		||||
    fish_indent --write ./run ./run.fish
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function run_hello -a command -d 'This is an example of a subgroup of commands'
 | 
			
		||||
    function hello_world -d 'The classic'
 | 
			
		||||
        echo 'Hello, world!'
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    function hello_name -a name -d 'Say hello to someone specific'
 | 
			
		||||
        echo "Hello, $name!"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    function hello_fr -d 'Say bonjour'
 | 
			
		||||
        echo 'Bonjour, le monde!'
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    alias hello_default='hello_world'
 | 
			
		||||
 | 
			
		||||
    execute_command 'hello' $command # this command comes from the run script
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue