Commit 2693a2fd authored by Jorge Bucaran's avatar Jorge Bucaran

%%% United States of the Fish → Wahoo + OMF %%%

parent 4d628d5f
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
# http://editorconfig.org
root = true
# Two-space indent, Unix-style newlines, and a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
custom/*
plugins/*
themes/*
pkg/**
!pkg/omf
!pkg/omf/**
.DS_Store
*.pyc
*~
*.sw?
plugins/ta/data/*
themes/**
!themes/default/*
# Track oh-my-fish plugin
!plugins/omf/
.DS_Store
**/.DS_Store
language: c
os:
- linux
- osx
env:
- FISH_PPA=nightly-master BREW_OPTIONS=--HEAD
before_install:
- script/bootstrap.sh
script: script/run-tests.fish
notifications:
email:
on_success: never
on_failure: change
webhooks:
urls:
- https://webhooks.gitter.im/e/16e8638d3a0deeaf317d
on_success: change
on_failure: always
on_start: false
sudo: false
addons:
apt:
packages:
- tree
- fish
before_script: pwd; tree -h
script: /bin/sh bin/install
after_script:
- cd ~/.config/fish; tree -h; find . -type f | xargs cat
<div align="center">
<a href="http://github.com/fish-shell/omf">
<img width=120px src="https://cloud.githubusercontent.com/assets/8317250/8510172/f006f0a4-230f-11e5-98b6-5c2e3c87088f.png">
</a>
</div>
<br>
<p align="center">
<b><a href="#issues">Issues</a></b>
|
<b><a href="#package-repositories">Packages</a></b>
|
<b><a href="#commit-messages">Commit Messages</a></b>
|
<b><a href="#code-style">Code Style</a></b>
</p>
# Contributing
We love pull requests. Here's a quick guide.
Thanks for taking the time to read this guide and please _do_ contribute to Oh My Fish. This is an open initiative and _everyone_ is welcome. :metal:
## Issues
Please [open an issue](https://github.com/fish-shell/omf/issues) for bug reports / patches. Include your OS version, code examples, stack traces and everything you can to help you debug your problem.
If you have a new feature or large change in mind, please open a new issue with your suggestion to discuss the idea together.
## Package Repositories
This is the repository for the core Oh My Fish framework and bootstrap installer.
If your issue is related to a specific package, we still may be able to help, but consider visiting that package's issue tracker first.
## Commit Messages
+ Use the [present tense](https://simple.wikipedia.org/wiki/Present_tense) ("add awesome-package" not "added ...")
+ Less than 72 characters or less for the first line of your commit.
+ Use of [emoji](http://www.emoji-cheat-sheet.com/) is definitely encouraged. :lollipop:
## Code Style
> These rules are not set in stone. Feel free to open an issue with suggestions and/or feedback.
### Control Flow
Using `if..else..end` blocks is preferred.
```fish
if not set -q ENV_VARIABLE
set -g ENV_VARIABLE 42
end
```
The following syntax is more concise, but arguably less transparent.
> You still may use `and` / `or` statements if you consider `if..else..then` to be overkill.
```fish
set -q VAR; set -g VAR 42
```
### Functions
Use named arguments `-a`:
```fish
function greet -a message
echo "$message"
end
```
Use `-d` description fields:
Fork and make your change. Make sure the tests pass:
```fish
function greet -a message -d "Display a greeting message"
echo "$message"
end
```
./script/run-tests.fish -v
`fish` does not have private functions, so in order to avoid polluting the global namespace, use a prefix based in the scope of your code. For example, if you are writing a `ninja` plugin using `__ninja_function_name`.
Push to your fork and [submit a pull request][pr].
If you are writing a function inside another function, prefix the inner one with the parent's name.
At this point you're waiting on us. We usually comment on pull requests within a few hours. We may suggest some changes or improvements or alternatives.
```fish
function parent
function parent_child
end
end
```
Some things that will increase the chance that your pull request is accepted:
Note that it's still possible to mimic private functions in `fish` by deleting the function before returning using `functions -e function_name`
* Write tests.
* Follow our [style guide][style].
* Write a [good commit message][commit].
```fish
function public_func
function private_func
# ...
functions -e private_func
end
end
```
## Style Guide
### Blocks
* Indentation should follow the "2-space convention".
* Keep line length to a maximum of 100 characters.
Blocks allow you to write code resembling macro expressions composed of smaller blocks without relying on variables.
### Plugins
Compare the following _without_ blocks:
If your plugin is complex, make sure to include tests, we suggest using [fish-spec][].
```fish
set -l colors green1 green2 green3
if test $error -ne 0
set colors red1 red2 red3
end
### Themes
for color in $colors
printf "%s"(set_color $color)">"
end
```
Make sure to include a screenshot in your pull request, but don't commit the file to git. A nifty way is to post a comment with the image and link directly to it.
and _using_ blocks:
```fish
for color in (begin
if test $error -ne 0
and printf "%s\n" red1 red2 red3
or printf "%s\n" green1 green2 green3
end)
printf "%s"(set_color $color)">"
end
```
[pr]: https://github.com/oh-my-fish/oh-my-fish/compare/
[fish-spec]: https://github.com/oh-my-fish/oh-my-fish/tree/master/plugins/fish-spec
[commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
[style]: #style-guide
The second example does not use a `colors` variable.
FROM ubuntu:latest
# Install dependencies
RUN apt-get -y install curl git software-properties-common
# Set bootstrap script environment variables
ENV FISH_PPA=nightly-master \
TRAVIS_OS_NAME=linux TRAVIS_REPO_SLUG=oh-my-fish/oh-my-fish TRAVIS_BRANCH=master
# Cache script folder
ADD script /src/script
# Install fish and oh-my-fish
RUN /src/script/bootstrap.sh
WORKDIR /root/.oh-my-fish
CMD ["fish", "./script/run-tests.fish", "--verbose"]
<div align="center">
<a href="http://github.com/fish-shell/omf">
<img width=120px src="https://cloud.githubusercontent.com/assets/8317250/8510172/f006f0a4-230f-11e5-98b6-5c2e3c87088f.png">
</a>
</div>
<br>
# FAQ
Thanks for taking the time to read this FAQ. Feel free to create a new issue if your question is not answered here.
## What is Oh My Fish and why do I want it?
Oh My Fish is a _framework_ for the [fishshell](https://fishshell.org). It helps you manage your configuration, themes and packages.
## What do I need to know to use Oh My Fish?
_Nothing_. You can install Oh My Fish and keep using Fish as usual. When you are ready to learn more just type `wa help`.
## What are Oh My Fish packages?
Oh My Fish packages are themes or plugins written in fish that extend the shell core functionality, run code during initialization, add auto completion for known utilities, etc.
## What kind of Oh My Fish packages are there?
There are roughly 3 kinds of packages:
1. Configuration utilities. For example [`pkg-pyenv`](https://github.com/oh-my-fish/pkg-pyenv) checks whether `pyenv` exists in your system and runs `(pyenv init - | psub)` for you during startup.
2. Themes. Check our [theme gallery](https://github.com/oh-my-fish).
3. Traditional shell utilities. For example [`pkg-copy`](https://github.com/oh-my-fish/pkg-copy), a clipboard utility compatible across Linux and OSX.
## What does Oh My Fish do exactly?
+ Autoload installed packages and themes under `$OMF_PATH/`.
+ Autoload your custom path. `$OMF_PATH/custom` by default, but configurable via `$OMF_CUSTOM`.
+ Autoload any `functions` directory under `$OMF_PATH` and `$OMF_CUSTOM`
+ Run `$OMF_CUSTOM/init.fish` if available.
## How can I upgrade from an existing Oh My Fish installation?
> :warning: Remember to backup your dotfiles and other sensitive data first.
```
rm -rf "$fish_path"
curl -L git.io/omf | sh
```
## I changed my prompt with `fish_config` and now I can't get my Oh My Fish theme's prompt back, what do I do?
`fish_config` persists the prompt to `~/.config/fish/functions/fish_prompt.fish`. That file gets loaded _after_ the Oh My Fish theme, therefore it takes precedence over the Oh My Fish theme's prompt. To restore your Oh My Fish theme prompt, simply remove that file by running:
```
rm ~/.config/fish/functions/fish_prompt.fish
```
## How do I use fish as my default shell?
Add Fish to `/etc/shells`:
```sh
echo "/usr/local/bin/fish" | sudo tee -a /etc/shells
```
Make Fish your default shell:
```sh
chsh -s /usr/local/bin/fish
```
To switch your default shell back:
> Substitute `/bin/bash` with `/bin/tcsh` or `/bin/zsh` as appropriate.
```sh
chsh -s /bin/bash
```
The MIT License (MIT)
Copyright (c) 2014 Bruno Ferreira Pinto
Copyright (c) 2015, Oh My Fish!
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
This diff is collapsed.
#!/bin/sh
#
# USAGE
# #1: curl -L git.io/omf | sh
# #2: curl -L git.io/omf > install && chmod +x install && ./install
# #3: OMF_CUSTOM=~/.dotfiles curl -L git.io/omf | sh
#
# ENV
# XDG_DATA_HOME Base directory (~/.local/share)
# XDG_CONFIG_HOME Base configuration directory (~/.config)
#
# ↑ See XDG Base Directory Specification
# → https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
#
# OMF_PATH Oh My Fish directory
# OMF_CONFIG Oh My Fish configuration
# OMF_CUSTOM Custom dotfiles directory
#
# OMF_REPO_URI Source git repository
# OMF_REPO_BRANCH Source repository default branch (master)
#
# FUNCTIONS
# die
# is_installed
# omf_create_fish_config <path/to/fish.config>
# omf_install
test -z ${XDG_DATA_HOME+_} && XDG_DATA_HOME="${HOME}/.local/share"
test -z ${XDG_CONFIG_HOME+_} && XDG_CONFIG_HOME="${HOME}/.config"
test -z ${OMF_PATH+_} && OMF_PATH="${XDG_DATA_HOME}/omf"
test -z ${OMF_CUSTOM+_} && OMF_CUSTOM="${HOME}/.dotfiles"
test -z ${OMF_CONFIG+_} && OMF_CONFIG="${XDG_CONFIG_HOME}/omf"
test -z ${OMF_REPO_URI+_} && OMF_REPO_URI="https://github.com/fish-shell/omf"
test -z ${OMF_REPO_BRANCH+_} && OMF_REPO_BRANCH="master"
die() {
echo "$1" && exit 1
}
is_installed() {
type "$1" >/dev/null 2>&1
}
omf_create_fish_config() {
local fish_config_file=$1
mkdir -p $(dirname "${fish_config_file}")
touch "${fish_config_file}"
}
omf_install() {
echo "Resolving Oh My Fish path → ${OMF_PATH}"
test -d "${OMF_PATH}" && die "Existing installation detected, aborting"
local git_uri="$(echo ${OMF_REPO_URI} | sed 's/\.git//').git"
echo "Cloning Oh My Fish → ${git_uri}"
if ! git clone -q --depth 1 -b "${OMF_REPO_BRANCH}" "${git_uri}" "${OMF_PATH}"; then
echo "Is 'git' installed?"
die "Could not clone the repository → ${OMF_PATH}:${OMF_REPO_BRANCH}"
fi
pushd ${OMF_PATH} >/dev/null 2>&1
local git_rev=$(git rev-parse HEAD) >/dev/null 2>&1
local git_upstream=$(git config remote.upstream.url)
if [ -z "${git_upstream}" ]; then
git remote add upstream ${git_uri}
else
git remote set-url upstream ${git_uri}
fi
echo "Oh My Fish revision id → ${git_rev}"
popd >/dev/null 2>&1
test -z ${FISH_CONFIG+_} && FISH_CONFIG="${XDG_CONFIG_HOME}/fish"
local fish_config_file="${FISH_CONFIG}/config.fish"
if [ -e "${FISH_CONFIG}/config.fish" ]; then
local timestamp=$(date +%s)
local fish_config_bk="${FISH_CONFIG}/config.${timestamp}.copy"
echo "Found existing 'fish' configuration → ${fish_config_file}"
echo "Writing back-up copy → ${fish_config_bk}"
cp "${fish_config_file}" "${fish_config_bk}" >/dev/null 2>&1
test $? -ne 0 && die "Writing back-up copy failed, error code → ${?}"
else
omf_create_fish_config $fish_config_file
fi
echo "Adding Oh My Fish bootstrap → ${fish_config_file}"
touch ${fish_config_file} >/dev/null 2>&1
test ! -w ${fish_config_file} && die "Fish configuration file is not writable, aborting."
echo "set -g OMF_PATH $(echo "${OMF_PATH}" | sed -e "s|$HOME|\$HOME|")" > ${fish_config_file}
echo "set -g OMF_CUSTOM $(echo "${OMF_CUSTOM}" | sed -e "s|$HOME|\$HOME|")" >> ${fish_config_file}
echo "set -g OMF_CONFIG $(echo "${OMF_CONFIG}" | sed -e "s|$HOME|\$HOME|")" >> ${fish_config_file}
echo "source \$OMF_PATH/init.fish" >> ${fish_config_file}
if [ ! -d "${OMF_CONFIG}" ]; then
echo "Writing Oh My Fish configuration → ${OMF_CONFIG}"
mkdir -p "${OMF_CONFIG}"
test -f "${OMF_CONFIG}/theme" || echo default > "${OMF_CONFIG}/theme"
test -f "${OMF_CONFIG}/revision" || echo ${git_rev} > "${OMF_CONFIG}/revision"
fi
}
echo "Installing Oh My Fish..."
! is_installed "fish" && die "Please install fish to continue → http://fishshell.com/"
if omf_install; then
echo "Oh My Fish successfully installed."
cd $HOME
# Do not swap process if running in a CI environment.
[ -z ${CI+_} ] || exit 0 && exec "fish" < /dev/tty
else
die "Oh My Fish couldn't install, but you can complain here → git.io/omf-issues"
fi
# Add yourself some shortcuts to projects you often work on
# Example:
#
# set oh-my-fish /Users/bpinto/.oh-my-fish
#
# Optionally add completions for your plugin here.
# complete -f -c my_command -a some_arg -d 'Description here'
# Add your own custom plugins in the custom/plugins directory. Plugins placed
# here will override ones with the same name in the main plugins directory.
https://github.com/wa/pkg-ansible
https://github.com/wa/pkg-battery
https://github.com/wa/pkg-copy
https://github.com/wa/pkg-direnv
https://github.com/cap10morgan/wa-emacs
https://github.com/wa/pkg-extract
https://github.com/wa/pkg-fasd
https://github.com/wa/pkg-gi
https://github.com/wa/pkg-hub
https://github.com/wa/pkg-keychain
https://github.com/wa/pkg-limap
https://github.com/wa/pkg-osx_manpath
https://github.com/wa/pkg-peco
https://github.com/wa/pkg-pyenv
https://github.com/wa/pkg-rbenv
https://github.com/wa/pkg-set_color
https://github.com/wa/pkg-stamp
https://github.com/wa/pkg-thefuck
https://github.com/wa/pkg-tiny
https://github.com/wa/theme-agnoster
https://github.com/oh-my-fish/theme-agnoster
https://github.com/oh-my-fish/theme-agnoster-mercurial
https://github.com/wa/theme-batman
https://github.com/oh-my-fish/theme-beloglazov
https://github.com/oh-my-fish/theme-bira
https://github.com/oh-my-fish/theme-bobthefish
https://github.com/oh-my-fish/theme-budspencer
https://github.com/oh-my-fish/theme-cbjohnson
https://github.com/oh-my-fish/theme-clearance
https://github.com/oh-my-fish/theme-cmorrell
https://github.com/oh-my-fish/theme-coffeeandcode
https://github.com/oh-my-fish/theme-cor
https://github.com/oh-my-fish/theme-dangerous
https://github.com/oh-my-fish/theme-eclm
https://github.com/oh-my-fish/theme-edan
https://github.com/oh-my-fish/theme-fishface
https://github.com/oh-my-fish/theme-fishy-drupal
https://github.com/oh-my-fish/theme-fisk
https://github.com/wa/theme-flash
https://github.com/oh-my-fish/theme-fox
https://github.com/oh-my-fish/theme-gianu
https://github.com/oh-my-fish/theme-gitstatus
https://github.com/oh-my-fish/theme-gnuykeaj
https://github.com/oh-my-fish/theme-godfather
https://github.com/wa/theme-hogan
https://github.com/wa/theme-hulk
https://github.com/oh-my-fish/theme-idan
https://github.com/oh-my-fish/theme-integral
https://github.com/oh-my-fish/theme-jacaetevha
https://github.com/oh-my-fish/theme-krisleech
https://github.com/oh-my-fish/theme-l
https://github.com/wa/theme-led
https://github.com/oh-my-fish/theme-mtahmed
https://github.com/oh-my-fish/theme-nai
https://github.com/oh-my-fish/theme-numist
https://github.com/oh-my-fish/theme-ocean
https://github.com/oh-my-fish/theme-perryh
https://github.com/oh-my-fish/theme-red-snapper
https://github.com/oh-my-fish/theme-robbyrussell
https://github.com/wa/theme-russell
https://github.com/oh-my-fish/theme-scorphish
https://github.com/oh-my-fish/theme-simplevi
https://github.com/oh-my-fish/theme-syl20bnr
https://github.com/oh-my-fish/theme-taktoa
https://github.com/oh-my-fish/theme-technopagan
https://github.com/oh-my-fish/theme-toaster
https://github.com/daveyarwood/tomita
https://github.com/oh-my-fish/theme-trout
https://github.com/oh-my-fish/theme-uggedal
https://github.com/oh-my-fish/theme-will
https://github.com/oh-my-fish/theme-yimmy
https://github.com/oh-my-fish/theme-zish
function Plugin --argument-names name
set -g fish_plugins $fish_plugins $name
if [ -e $fish_path/plugins/$name -o -e $fish_custom/plugins/$name ]
import plugins/$name
else
set_color red
echo "Plugin '$name' is not installed. Run 'omf install' to download and install it."
set_color normal
end
end
function Theme --argument-names name
set -g fish_theme $name
if [ -e $fish_path/themes/$name -o -e $fish_custom/themes/$name ]
import themes/$name
else
set_color red
echo "Theme '$name' is not installed. Run 'omf install' to download and install it."
set_color normal
end
end
# NAME
# _prepend_path - adds a path to a list
#
# SYNOPSIS
# _prepend_path [-d --destination <destination path>] <path>
#
# DESCRIPTION
# Adds a path to a list.
# If no list specified, defaults to $PATH
#
# OPTIONS
# <path>
# Required. Specify the path to add to the list.
# OPERATORS
# -d <DESTINATION PATH>
# Should appear at the end if used. Specifies the name of the
# list to prepend the paths to.
# If not used, $PATH is assumed by default.
#
# EXAMPLES
# _prepend_path $path
# Add $path to $PATH
#
# _prepend_path $path -d $fish_function_path
# Add $path to $fish_function_path
#/
function _prepend_path
# $PATH is the default destination path
set -l destination_path PATH
set -l path $argv
if test (count $argv) -gt 2
switch $path[-2]
case -d --destination
set destination_path $path[-1]
set path $path[1..-3]
end
end
for path in $path
if test -d $path
if not contains $path $$destination_path
set $destination_path $path $$destination_path
end
end
end
end
# NAME
# _prepend_tree - add a dependency tree to fish_function_path
#
# SYNOPSIS
# _prepend_tree [-v --verbose] <path> [<glob>..]
#
# DESCRIPTION
# Search a path tree and prepend directories with fish files. Use a glob
# list to include or exclude other file extensions. Use -v --verbose to
# output directories to be added to the path.
#
# OPTIONS
# [-v --verbose]
# Optional. Print directories that match the glob. Must be the
# first argument if used.
#
# <path>
# Required. Specify the path to search for glob patterns.
#
# [<glob> [<operator> <glob>..]]
# Glob pattern to match when traversing the path path.
#
# OPERATORS
# [! -not glob]
# Negates the following glob.
#
# [<glob> -o -or <glob>..]
# Default. Must meet at least one listed criteria.
#
# [<glob> [-a -and <glob>..]]
# Must meet *all* listed criteria.
#
# EXAMPLES
# _prepend_tree $path
# Match directories in $path containing `.fish` files.
#
# _prepend_tree $path \*.fish \*.sh
# Match directories in $path with either `.fish` OR `.sh` files.
#
# _prepend_tree $path \*.fish -a ! _\*.\*
# Match directories with `.fish` files that do not start with `_`.
#
# AUTHORS
# Jorge Bucaran <jbucaran@me.com>
#
# SEE ALSO
# .oh-my-fish/functions/_prepend_path.fish
#
# v.0.2.0
#/
function _prepend_tree -d "Add a dependency tree to the Fish path."
# Match directories with .fish files always.
set -l glob -name \*.fish
set -l verbose ""
# Retrieve first argument, either the path or the -v option.
set -l path $argv[1]
if contains -- $path -v --verbose
set verbose -v
# Option first, path should be next.
set path $argv[2]
end
# Parse glob options to create the main glob pattern.
if [ (count $argv) -gt 2 ]
set -l operator -o
for option in $argv[3..-1]
switch $option
case ! -not
set operator $operator !
case -o -or
set operator -o
case -a -and
set operator -a
case "*"
if [ operator = ! ]
set glob $operator $glob
else
set glob $glob $operator
end
set glob $glob -name $option
set operator -o # Default
end
end
end
# Traverse $path prepending only directories with matches. Excludes completions folder.
test -d $path
and for dir in (find $path ! -name "completions" ! -path "*.git*" -type d)
# Use head to retrieve at least one match. Skip not found errors
# for directories that do not exist.
if [ -z (find "$dir" $glob -maxdepth 1 ^/dev/null | head -1) ]
continue
end
# Print matched directories if the -v option is set.
if not [ -z $verbose ]
printf "%s\n" $dir
end
# Prepend matched directory to the the global fish function path.
# Note path duplicates are already handled by _prepend_path.
_prepend_path $dir -d fish_function_path
end
end
# NAME
# import - load libraries, plugins, themes, etc.
#
# SYNOPSIS
# import <path/library>[<path/library>..]
#
# DESCRIPTION
# Import libraries, plugins, themes, completions. Prepend existing
# user custom/<library> directories to the path to allow users to
# override specific functions in themes/plugins.
#
# NOTES
# $fish_path and $fish_custom point to oh-my-fish home and the user
# dotfiles folder respectively. Both globals are usually configured
# in ~/.config/fish/config.fish. Also, import is clever enough to
# skip directories with *.spec.fish files.
#
# EXAMPLES
# import plugins/<plugin>
# import plugins/{dpaste,cask} themes/bobthefish
#
# AUTHORS
# Jorge Bucaran <jbucaran@me.com>
#
# SEE ALSO
# functions/_prepend_path.fish
# functions/_prepend_tree.fish
#
# v.0.1.1
#/
function import -d "Load libraries, plugins, themes, etc."
# Do not add spec files to function path.
set -l skip_spec \*.fish -a ! \*.spec.fish
for library in $argv
# Prepend plugins, themes and completions, traversing library
# trees and prepending directories with fish code.
_prepend_tree $fish_path/$library $skip_spec
_prepend_tree $fish_custom/$library $skip_spec
_prepend_path $fish_path/$library/completions -d fish_complete_path
_prepend_path $fish_custom/$library/completions -d fish_complete_path
# Set path to load files.
set -l path $library/(basename $library).load
# Source each plugin, theme, etc., configuration load file.
for load in $fish_path/$path $fish_custom/$path
if [ -e $load ]
. $load
end
end
end
end
function restore_original_fish_colors
# Regular syntax highlighting colors
set fish_color_normal normal
set fish_color_command 005fd7 purple
set fish_color_param 00afff cyan
set fish_color_redirection normal
set fish_color_comment red
set fish_color_error red --bold
set fish_color_escape cyan
set fish_color_operator cyan
set fish_color_quote brown
set fish_color_autosuggestion 555 yellow
set fish_color_valid_path --underline
set fish_color_cwd green
set fish_color_cwd_root red
# Background color for matching quotes and parenthesis
set fish_color_match cyan
# Background color for search matches
set fish_color_search_match --background=purple
# Pager colors
set fish_pager_color_prefix cyan
set fish_pager_color_completion normal
set fish_pager_color_description 555 yellow
set fish_pager_color_progress cyan
end
# Cloned from https://github.com/fish-shell/fish-shell/issues/522
function source_script --description 'Source sh/csh file'
set -l ext
set -l type
while true
switch $argv[1]
case '--sh'
set type sh
case '--csh'
set type csh
case '--bash'
set type bash
case '--ext'
set ext 1
case '*'
break
end
set -e argv[1]
end
if not test "$type"
for f in $argv
switch $f
case '*.sh'
set type bash
break
case '*.csh' '*.tcsh'
set type csh
break
end
end
end
set -l exe
set -l source
switch "$type"
case bash
set exe /bin/bash
set source .
case sh
set exe /bin/sh
set source .
case csh
set exe /bin/tcsh
set source source
case '*'
echo Unknown source type for "'$argv'"
end
if test "$ext"
eval "exec $exe -c '$source $argv; exec fish'"
else
set -l f1 (command mktemp -t tmp.XXXXXXXXXX)
set -l f2 (command mktemp -t tmp.XXXXXXXXXX)
eval $exe -c "'env | sort > $f1; $source $argv; env | sort > $f2'"
set -l filter "(^[^\+-]|^\+\+\+|^---|^[\+-]_|^[\+-]PIPESTATUS|^[\+-]COLUMNS)"
set -l pattern 's/[:]\{0,1\}\([^:]\+\)/"\1" /g'
set -l IFS '='
set -l diffopts --old-line-format '-=%L' --new-line-format '+=%L' --unchanged-line-format ''
command diff $diffopts $f1 $f2 | command grep -vE $filter | while read -l state var value
switch $state$var
case -PATH
continue
case +PATH
eval set value (echo $value | tr : ' ')
for pt in $value
contains $pt $PATH; and continue
if not test -d $pt
echo "Unable to add '$pt' to \$PATH. Check existance."
continue
end
set -gx PATH $PATH $pt > /dev/null
end
case '-*'
set -e $var
case '+*'
eval set -gx $var (echo $value | command sed $pattern)
case '*'
echo Source error! Invalid case "'$state$var'"
end
end
command rm $f1 $f2 > /dev/null
end
end
# SYNOPSIS
# Initialize Oh My Fish.
#
# ENV
# OSTYPE Operating system.
# RESET_PATH Original $PATH preseved across Oh My Fish refreshes.
# OMF_PATH Set in ~/.config/fish/config.fish
# OMF_IGNORE List of packages to ignore.
# OMF_CUSTOM Same as OMF_PATH. ~/.dotfiles by default.
#
# OVERVIEW
# + Autoload Oh My Fish packages, themes and custom path
# + For each <pkg> inside {$OMF_PATH,$OMF_CUSTOM}
# + Autoload <pkg> directory
# + Source <pkg>.fish
# + Emit init_<pkg> event
#
# + Autoload {$OMF_PATH,$OMF_CUSTOM}/functions
# + Source {$OMF_PATH,$OMF_CUSTOM} → fish-shell/fish-shell/issues/845
# + Source $OMF_CUSTOM/init.fish
if set -q RESET_PATH
set PATH $RESET_PATH
else
set -gx RESET_PATH $PATH
end
set -q OSTYPE; or set -g OSTYPE (uname)
# Save the head of function path and autoload Oh My Fish core functions
set -l user_function_path $fish_function_path[1]
set fish_function_path[1] $OMF_PATH/lib
set -l theme {$OMF_PATH,$OMF_CUSTOM}/themes/(cat $OMF_CONFIG/theme)
set -l paths $OMF_PATH/pkg/*
set -l custom $OMF_CUSTOM/pkg/*
set -l ignore $OMF_IGNORE
for path in $paths
set custom $OMF_CUSTOM/(basename $path) $custom
end
for path in $OMF_PATH/lib $OMF_PATH/lib/git $paths $theme $custom
contains -- (basename $path) $ignore; and continue
autoload $path $path/completions
source $path/(basename $path).fish
and emit init_(basename $path) $path
end
autoload $OMF_CUSTOM/functions
autoload $user_function_path
source {$OMF_PATH,$OMF_CUSTOM}/events.fish
source $OMF_CUSTOM/init.fish
<p align="center">
<a href="https://github.com/fish-shell/omf/blob/master/README.md">
<img width="100px" src="https://cloud.githubusercontent.com/assets/8317250/8510172/f006f0a4-230f-11e5-98b6-5c2e3c87088f.png">
</a>
</p>
# Core Library
## Basic Functions
#### `autoload` _`<path [path...]>`_
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`.
```fish
autoload $mypath $mypath/completions
```
#### `available` _`<name>`_
Check if a program is available to run. Sets `$status` to `0` if the program is available.
Use this function to check if a plugin is available before using it:
```fish
if available battery
battery
end
```
#### `basename` _`<path> ...`_
Wrap basename so it can handle multiple arguments.
#### `refresh`
Extract the root (top-most parent directory), dirname and basename from [`fish_prompt`](http://fishshell.com/docs/current/faq.html#faq-prompt).
#### `prompt_segments`
Replace the running instance of fishshell with a new one causing Oh My Fish to reload as well.
## Git Functions
#### `git_ahead`
Echo a character that represents whether the current repo is ahead, behind or has diverged from its upstream.
##### Default values:
+ ahead: `+`
+ behind: `-`
+ diverged: `±`
+ none: ` `
#### `git_is_repo`
Set `$status` to `0` if the current working directory belongs to a git repo.
#### `git_branch_name`
Echo the currently checked out branch name of the current repo.
#### `git_is_dirty`
Set `$status` to `0` if there are any changes to files already being tracked in the repo.
#### `git_is_staged`
Set `$status` to `0` if there [staged](http://programmers.stackexchange.com/questions/119782/what-does-stage-mean-in-git) changes.
#### `git_is_stashed`
Set `$status` to `0` if there are items in the [stash](https://git-scm.com/book/en/v1/Git-Tools-Stashing).
#### `git_is_touched`
Set `$status` to `0` if the repo has any changes whatsoever, including [tracked or untracked](http://stackoverflow.com/questions/9663507/what-is-tracked-files-and-untracked-files-in-the-context-of-git) files.
#### `git_untracked`
Echo a `\n` separated list of untracked files.
# SYNOPSIS
# autoload <path [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.
function autoload -d "autoload a function or completion path"
for path in $argv
if test -d "$path"
set -l dest fish_function_path
if test (basename "$path") = "completions"
set dest fish_complete_path
end
contains "$path" $$dest; or set $dest "$path" $$dest
end
end
end
# SYNOPSIS
# available [name]
#
# OVERVIEW
# Check if a program is available.
function available -a program -d "check if a program is available."
type "$program" ^/dev/null >&2
end
# SYNOPSIS
# basename <string> [suffix]
# basename [-s suffix] <string> [string...]
#
# OVERVIEW
# osx style variable arguments basename
function basename -d "get the filename or directory part of a path"
if test (uname) = "Darwin"
command basename $argv
else
if set -q argv[1]
set -l ext ""
switch $argv[1]
case -s
if test (count $argv) -gt 2
set ext $argv[2]
set argv $argv[3..-1]
else
echo "basename: Invalid number of arguments"
return 1
end
end
for path in $argv
command basename "$path" "$ext"
end
end
end
end
function git_ahead -a ahead behind diverged none
git_is_repo; and begin
test -z "$ahead"; and set ahead "+"
test -z "behind"; and set behind "-"
test -z "diverged"; and set diverged "±"
test -z "none"; and set none ""
command git rev-list --left-right "@{upstream}...HEAD" ^/dev/null \
| awk "/>/ {a += 1} /</ {b += 1} \
{if (a > 0) nextfile} END \
{if (a > 0 && b > 0) print \"$diverged\"; \
else if (a > 0) print \"$ahead\"; \
else if (b > 0) print \"$behind\";
else printf \"$none\"}"
end
end
function git_branch_name -d "Get current branch name"
git_is_repo; and begin
command git symbolic-ref --short HEAD
end
end
function git_is_dirty -d "Check if there are changes to tracked files"
git_is_repo; and not command git diff --no-ext-diff --quiet --exit-code
end
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment