{% if not SHIMS_ONLY -%} # This function is used to run the omni command, and then operate on # the requested shell changes from the command (changing current # working directory, environment, etc.); this is why we require using # a shell function for this, instead of simply calling the omni # command from the path function omni # Prepare the environment for omni set -gx OMNI_UUID (uuidgen) set -q TMPDIR; and set -l tmpdir $TMPDIR; or set -l tmpdir /tmp set -gx OMNI_FILE_PREFIX "omni_$OMNI_UUID" set -gx OMNI_CMD_FILE "$tmpdir/$OMNI_FILE_PREFIX.cmd" set -gx OMNI_SHELL "fish" # Run the command {{OMNI_BIN}} $argv set EXIT_CODE $status # Check if OMNI_CMD_FILE exists, and if it does, run the commands # inside without a subshell, so that the commands can modify the # environment of the current shell, and then delete the file if test -f $OMNI_CMD_FILE; and test $EXIT_CODE -eq 0 cat $OMNI_CMD_FILE | while read -l cmd eval $cmd set EXIT_CODE $status if test $EXIT_CODE -ne 0 echo -e "\033[96momni:\033[0m \033[31mcommand failed:\033[0m $cmd \033[90m(exit: $EXIT_CODE)\033[0m" break end end end # Delete the files using background process to avoid delay # in returning to the prompt, and within a subshell to disable # monitor mode (set +m) and hide the '[x] Done' message commandline -M find "$tmpdir/" -name "$OMNI_FILE_PREFIX*" -exec echo rm {} \; >/dev/null 2>&1 & # Unset the environment variables set -e OMNI_SHELL set -e OMNI_UUID set -e OMNI_FILE_PREFIX set -e OMNI_CMD_FILE # Return the exit code of the command return $EXIT_CODE end {% if OMNI_ALIASES or OMNI_COMMAND_ALIASES -%} # Setup aliases for omni {% for alias in OMNI_ALIASES -%} alias {{alias}}="omni" {% endfor -%} {% for alias in OMNI_COMMAND_ALIASES -%} alias {{alias.alias}}={{alias.full_command}} {% endfor %} {% endif -%} # Setup autocompletion for omni function _omni_complete_fish set -f cur (commandline -o) set -f prev (commandline -P) set -f cmdline (commandline --tokenize --cut-at-cursor) set -f orig_cmdline_size (count $cmdline) set -f cword (count $cmdline) set -f autocomplete omni --complete {% if OMNI_COMMAND_ALIASES -%} # Handle command aliases # Get the first word to check if it is a command alias switch $cmdline[1] {% for alias in OMNI_COMMAND_ALIASES -%} case "{{alias.alias}}" set -f autocomplete $autocomplete {{alias.command}} set -f cword (math $cword + {{alias.command_size}}) {% endfor -%} case '*' # Not a command alias end {% endif -%} # Remove the first element (command) from cmdline set -l args $cmdline[2..-1] set -f opts (env COMP_CWORD=$cword OMNI_SHELL=fish $autocomplete $args) string join \n -- $opts end complete -c omni -a "(_omni_complete_fish)" -f {% if OMNI_ALIASES or OMNI_COMMAND_ALIASES -%} {% for alias in OMNI_ALIASES -%} complete -c {{alias}} -a "(_omni_complete_fish)" -f {% endfor -%} {% for alias in OMNI_COMMAND_ALIASES -%} complete -c {{alias.alias}} -a "(_omni_complete_fish)" -f {% endfor %} {% endif -%} # Setup the prompt hook to load the dynamic environment function __omni_hook --on-event fish_prompt --on-variable PWD OMNI_SHELL=fish OMNI_SHELL_PPID=$fish_pid {{OMNI_BIN}} hook env{% if KEEP_SHIMS %} --keep-shims{% endif %} fish \ | while read line eval "$line" 2>/dev/null end end {% endif -%} # Add the shims directory to the PATH, so that the dynamic # environment can be used in non-interactive shells. # This will automatically be removed from the PATH when the # dynamic environment is loaded, allowing to favor it over # the shims set -l omni_shims_path {{ OMNI_SHIMS }} if not contains $omni_shims_path $PATH set -l PATH $omni_shims_path $PATH set -gx PATH $PATH end