mirror of
https://github.com/oh-my-fish/oh-my-fish.git
synced 2024-11-23 05:55:39 +08:00
commit
a1243f659f
16
init.fish
16
init.fish
|
@ -41,16 +41,20 @@ source $OMF_CONFIG/before.init.fish ^/dev/null
|
|||
set -l user_function_path $fish_function_path[1]
|
||||
set fish_function_path[1] $OMF_PATH/lib
|
||||
|
||||
set -l theme {$OMF_PATH,$OMF_CONFIG}/themes/(cat $OMF_CONFIG/theme)
|
||||
# Autoload util functions
|
||||
autoload $OMF_PATH/lib $OMF_PATH/lib/git
|
||||
|
||||
for path in $OMF_PATH/lib $OMF_PATH/lib/git {$OMF_PATH,$OMF_CONFIG}/pkg/* $theme
|
||||
contains -- (basename $path) $OMF_IGNORE; and continue
|
||||
for path in {$OMF_PATH,$OMF_CONFIG}/pkg/*
|
||||
set -l name (basename $path)
|
||||
|
||||
autoload $path $path/completions
|
||||
source $path/(basename $path).fish ^/dev/null
|
||||
and emit init_(basename $path) $path
|
||||
contains -- $name $OMF_IGNORE; and continue
|
||||
require $name
|
||||
end
|
||||
|
||||
# Autoload theme
|
||||
autoload {$OMF_PATH,$OMF_CONFIG}/themes/(cat $OMF_CONFIG/theme)
|
||||
|
||||
# Autoload custom functions
|
||||
autoload $OMF_CONFIG/functions
|
||||
autoload $user_function_path
|
||||
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
# SYNOPSIS
|
||||
# autoload <path [path...]>
|
||||
# autoload <path>...
|
||||
#
|
||||
# OVERVIEW
|
||||
# Autoload a function or completion path. Add the specified list of
|
||||
# directories to $fish_function_path. Any `completions` directories
|
||||
# are correctly added to the $fish_complete_path.
|
||||
#
|
||||
# Returns 0 if one of the paths exist.
|
||||
# Returns != 0 if all paths are missing.
|
||||
|
||||
function autoload -d "autoload a function or completion path"
|
||||
for path in $argv
|
||||
set -l dest fish_function_path
|
||||
|
||||
if test -d "$path"
|
||||
set -l dest fish_function_path
|
||||
set path_exist
|
||||
|
||||
if test (basename "$path") = completions
|
||||
set dest fish_complete_path
|
||||
|
@ -18,4 +23,6 @@ function autoload -d "autoload a function or completion path"
|
|||
contains "$path" $$dest; or set $dest "$path" $$dest
|
||||
end
|
||||
end
|
||||
|
||||
set -q path_exist
|
||||
end
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
# available [name]
|
||||
#
|
||||
# OVERVIEW
|
||||
# Check if a program is available.
|
||||
# Check if a function or program is available.
|
||||
|
||||
function available -a program -d "check if a program is available."
|
||||
type "$program" ^/dev/null >&2
|
||||
function available -a name -d "Check if a function or program is available."
|
||||
type "$name" ^/dev/null >&2
|
||||
end
|
||||
|
|
26
lib/require.fish
Normal file
26
lib/require.fish
Normal file
|
@ -0,0 +1,26 @@
|
|||
# SYNOPSIS
|
||||
# require [name]
|
||||
#
|
||||
# OVERVIEW
|
||||
# Require a plugin:
|
||||
# - Autoload its functions and completions.
|
||||
# - Source its initialization file.
|
||||
# - Emit its initialization event.
|
||||
#
|
||||
# If the required plugin has already been loaded, does nothing.
|
||||
|
||||
function require -a name
|
||||
# Skip if plugin has already been loaded.
|
||||
contains -- $OMF_PATH/pkg/$name $fish_function_path;
|
||||
or contains -- $OMF_CONFIG/pkg/$name $fish_function_path;
|
||||
and return 0
|
||||
|
||||
for path in {$OMF_PATH,$OMF_CONFIG}/pkg/$name
|
||||
if autoload $path $path/completions
|
||||
|
||||
source $path/init.fish ^/dev/null;
|
||||
or source $path/$name.fish ^/dev/null;
|
||||
and emit init_$name $path
|
||||
end
|
||||
end
|
||||
end
|
3
pkg/omf/init.fish
Normal file
3
pkg/omf/init.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function init -a path --on-event init_omf
|
||||
autoload $path/cli $path/util
|
||||
end
|
|
@ -29,10 +29,6 @@ function omf::off
|
|||
set_color normal
|
||||
end
|
||||
|
||||
function init -a path --on-event init_omf
|
||||
autoload $path/cli $path/util
|
||||
end
|
||||
|
||||
function omf -d "Oh My Fish"
|
||||
if test (count $argv) -eq 0
|
||||
omf.help "main"; and return 0
|
||||
|
|
Loading…
Reference in New Issue
Block a user