mirror of
https://github.com/oh-my-fish/oh-my-fish.git
synced 2025-01-21 15:14:59 +08:00
Merge pull request #468 from bobthecow/subtree-split
Move all plugins and themes to oh-my-fish repos.
This commit is contained in:
commit
6497460309
|
@ -1,7 +0,0 @@
|
|||
if test -n "$ANDROID_SDK_ROOT"
|
||||
_prepend_path $ANDROID_SDK_ROOT/tools
|
||||
_prepend_path $ANDROID_SDK_ROOT/platform-tools
|
||||
else
|
||||
_prepend_path /opt/android-sdk/tools
|
||||
_prepend_path /opt/android-sdk/platform-tools
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
|
||||
# The Arch Linux Plugins
|
||||
|
||||
The Arch Linux Plugins provides a number of plugins to make using arch easier.
|
||||
|
||||
# The Plugins
|
||||
|
||||
## archlinux
|
||||
|
||||
This plugin includes all of provided Arch Linux Plugins wrapped in a single plugin.
|
||||
|
||||
To use this plugin append the following `archlinux` to `fish_plugins`.
|
||||
|
||||
## archlinux/pacman
|
||||
|
||||
This plugin makes working with pacman easier and faster. Please refer to pacman/README.md for more information.
|
||||
|
||||
To use this plugin append the following `archlinux/pacman` to `fish_plugins`.
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
|
||||
set -l current_dir (dirname $argv)
|
||||
|
||||
# add pacman related functions
|
||||
set fish_function_path $current_dir/pacman $fish_function_path
|
|
@ -1,52 +0,0 @@
|
|||
|
||||
# pacman functions #
|
||||
|
||||
* pacin
|
||||
Install specific package(s) from the repositories
|
||||
|
||||
* pacins
|
||||
Install specific package not from the repositories but from a file
|
||||
|
||||
* pacre
|
||||
Remove the specified package(s), retaining its configuration(s) and required dependencies
|
||||
|
||||
* pacrem
|
||||
Remove the specified package(s), its configuration(s) and unneeded dependencies
|
||||
|
||||
* pacrep
|
||||
Display information about a given package in the repositories
|
||||
|
||||
* pacreps
|
||||
Search for package(s) in the repositories
|
||||
|
||||
* pacloc
|
||||
Display information about a given package in the local database
|
||||
|
||||
* paclocs
|
||||
Search for package(s) in the local database
|
||||
|
||||
* pacupd
|
||||
Update and refresh the local package and ABS databases against repositories
|
||||
|
||||
* pacinsd
|
||||
Install given package(s) as dependencies of another package
|
||||
|
||||
* pacmir
|
||||
Force refresh of all package lists after updating /etc/pacman.d/mirrorlist
|
||||
|
||||
* paclist
|
||||
List all installed packages with a short description - Source
|
||||
|
||||
* paclsorphans
|
||||
List all orphaned packages
|
||||
|
||||
* pacrmorphans
|
||||
Delete all orphaned packages
|
||||
|
||||
* pacdisowned | less +F
|
||||
List all disowned files in your system
|
||||
|
||||
|
||||
# Based on aliases from oh-my-zsh
|
||||
|
||||
Source: https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/archlinux/archlinux.plugin.zsh
|
|
@ -1,22 +0,0 @@
|
|||
function pacdisowned -d "Display list of disowned files"
|
||||
if test -d "$TMPDIR"
|
||||
set tmp $TMPDIR
|
||||
else
|
||||
set tmp "/tmp"
|
||||
end
|
||||
set dir (mktemp -d -p $tmp)
|
||||
|
||||
set -l fs "$dir/fs"
|
||||
set -l db "$dir/db"
|
||||
|
||||
pacman -Qlq | sort -u > "$db"
|
||||
|
||||
find /bin /etc /lib /sbin /usr ! -name lost+found \
|
||||
\( -type d -printf '%p/\n' -o -print \) | sort > "$fs"
|
||||
|
||||
comm -23 "$fs" "$db"
|
||||
|
||||
# clean-up after ourself
|
||||
rm -rf "$dir"
|
||||
end
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
function pacin -d "Install specific package(s) from the repositories"
|
||||
sudo pacman -S $argv
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function pacins -d "Install specific package not from the repositories but from a file"
|
||||
sudo pacman -U $argv
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function paclist
|
||||
pacman -Qei (pacman -Qu|cut -d" " -f 1)|awk ' BEGIN {FS=":"}/^Name/{printf("\033[1;36m%s\033[1;37m", $2)}/^Description/{print $2}'
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function pacloc -d "Display information about a given package in the local database"
|
||||
pacman -Qi $argv
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function paclocs -d "Search for package(s) in the local database"
|
||||
pacman -Qs $argv
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function paclsorphans -d "Display a list of packages that were installed as dependencies but are no longer required by any installed package"
|
||||
pacman -Qdt $argv
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function pacmanallkeys -d "Get all keys for developers and trusted users"
|
||||
curl https://www.archlinux.org/developers/ https://www.archlinux.org/trustedusers/ | awk -F\" '(/pgp.mit.edu/) {sub(/.*search=0x/,"");print $1}' | xargs sudo pacman-key --recv-keys
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
function pacmansignkeys -d "Allow user to sign keys"
|
||||
for key in $argv;
|
||||
sudo pacman-key --recv-keys $key
|
||||
sudo pacman-key --lsign-key $key
|
||||
printf 'trust\n3\n' | sudo gpg --homedir /etc/pacman.d/gnupg \
|
||||
--no-permission-warning --command-fd 0 --edit-key $key
|
||||
end
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function pacmir -d "Force refresh of all package lists after updating /etc/pacman.d/mirrorlist"
|
||||
sudo pacman -Syy $argv
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function pacre -d "Remove the specified package(s), retaining its configuration(s) and required dependencies"
|
||||
sudo pacman -R $argv
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function pacrem -d "Remove the specified package(s), its configuration(s) and unneeded dependencies"
|
||||
sudo pacman -Rns $argv
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function pacrep -d "Display information about a given package in the repositories"
|
||||
pacman -Si $argv
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function pacreps -d "Search for package(s) in the repositories"
|
||||
pacman -Ss $argv
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function pacrmorphans -d "Remove all real orphan packages"
|
||||
sudo pacman -Rs (pacman -Qtdq) $argv
|
||||
end
|
|
@ -1,10 +0,0 @@
|
|||
which abs ^ /dev/null > /dev/null
|
||||
if test $status -ne 1
|
||||
function pacupd -d "Update and refresh the local package and ABS databases against repositories"
|
||||
sudo pacman -Sy; and sudo abs
|
||||
end
|
||||
else
|
||||
function pacupd -d "Update and refresh the local package against repositories"
|
||||
sudo pacman -Sy
|
||||
end
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function pacupg -d "Synchronize with repositories before upgrading packages that are out of date on the local system."
|
||||
sudo pacman -Syu $argv
|
||||
end
|
|
@ -1,60 +0,0 @@
|
|||
function __bak_help
|
||||
echo -e \
|
||||
"Usage:
|
||||
$argv[1] SOURCE..."
|
||||
end
|
||||
|
||||
function __bak_parse_help
|
||||
if [ (count $argv) -lt 3 ]
|
||||
__bak_help $argv[1]
|
||||
else
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
function __bak_name
|
||||
# trim / for directories
|
||||
set file (echo $argv[1] | sed 's/\/*$//')
|
||||
echo "$file."(date +'%Y%m%d_%H%M%S')".bak"
|
||||
end
|
||||
|
||||
function __bak
|
||||
__bak_parse_help $argv
|
||||
or begin
|
||||
set program $argv[2]
|
||||
for file in $argv[3..-1]
|
||||
eval $program $file (__bak_name $file)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
set -g __bak_re '(.*)\.[0-9]{8,8}_[0-9]{6,6}\.bak\/*$'
|
||||
|
||||
function __is_bak
|
||||
set file $argv[1]
|
||||
echo "$file" | grep -Eq $__bak_re
|
||||
end
|
||||
|
||||
function __bak_normalized
|
||||
set file $argv[1]
|
||||
echo "$file" | sed -E "s/$__bak_re/\1/g"
|
||||
end
|
||||
|
||||
function __unbak
|
||||
__bak_parse_help $argv
|
||||
or begin
|
||||
set program $argv[2]
|
||||
for file in $argv[3..-1]
|
||||
set normalized (__bak_normalized $file)
|
||||
if test ! -e $file
|
||||
echo "File \"$file\" not exists! Cannot unbak \"$file\"."
|
||||
else if not __is_bak $file
|
||||
echo "File \"$file\" don't meet bak files convention! Cannot unbak \"$file\"."
|
||||
else if test -e $normalized
|
||||
echo "File \"$normalized\" exists! Cannot unbak \"$file\"."
|
||||
else
|
||||
eval $program $file $normalized
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +0,0 @@
|
|||
# Function to copy files and directories (a.txt copy to a.txt.20140608_195859.bak)
|
||||
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
|
||||
|
||||
function cpbak --description 'Copy files to make a backup copies'
|
||||
__bak cpbak 'cp -a' $argv
|
||||
end
|
|
@ -1,6 +0,0 @@
|
|||
# Function to rename files and directories (a.txt rename to a.txt.20140608_195859.bak)
|
||||
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
|
||||
|
||||
function mvbak --description 'Rename files to make a backup copies'
|
||||
__bak mvbak mv $argv
|
||||
end
|
|
@ -1,6 +0,0 @@
|
|||
# Function to copy files and directories (a.txt.20140608_195859.bak copy to a.txt)
|
||||
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
|
||||
|
||||
function uncpbak --description 'Copy files to revert a backup copies to a normal files'
|
||||
__unbak uncpbak 'cp -a' $argv
|
||||
end
|
|
@ -1,6 +0,0 @@
|
|||
# Function to move files and directories (a.txt.20140608_195859.bak move to a.txt)
|
||||
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
|
||||
|
||||
function unmvbak --description 'Move files to revert a backup copies to a normal files'
|
||||
__unbak unmvbak mv $argv
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
# A better alias provide completion
|
||||
|
||||
Use `balias` instead of `alias`,you can get same completion meanwhile you set alias.
|
||||
|
||||
# Example
|
||||
|
||||
```
|
||||
balias apti 'sudo apt-get install'
|
||||
balias gc 'git checkout'
|
||||
```
|
||||
|
||||
Then,you will get
|
||||
|
||||
![apti](http://www.geekpics.net/images/2014/08/23/TJn6kfBY.png)
|
||||
|
||||
![gc](http://www.geekpics.net/images/2014/08/23/655x76xcPJolvxqra.png.pagespeed.ic.4S9hgPfZ53.png)
|
|
@ -1,10 +0,0 @@
|
|||
function balias --argument alias command
|
||||
eval 'alias $alias $command'
|
||||
if expr $command : '^sudo '>/dev/null
|
||||
set command (echo "$command" | cut -c6-)
|
||||
end
|
||||
complete -c $alias -xa "(
|
||||
set -l cmd (commandline -pc | sed -e 's/^ *\S\+ *//' );
|
||||
complete -C\"$command \$cmd\";
|
||||
)"
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
import plugins/fish-spec
|
||||
import plugins/balias
|
||||
|
||||
function describe_library -d "balias: better-alias"
|
||||
|
||||
function after_all
|
||||
functions -e changedir
|
||||
functions -e ls_as_root
|
||||
end
|
||||
|
||||
function it_doesnt_fail
|
||||
balias changedir cd
|
||||
expect $status --to-equal 0
|
||||
end
|
||||
|
||||
function it_defines_an_alias
|
||||
balias changedir cd
|
||||
set -l ignore_output (functions changedir)
|
||||
expect $status --to-equal 0
|
||||
end
|
||||
|
||||
function you_can_use_the_alias
|
||||
mkdir testdir
|
||||
changedir testdir
|
||||
expect test $status --to-be-true
|
||||
cd ..
|
||||
rmdir testdir
|
||||
end
|
||||
|
||||
function it_chops_off_sudo
|
||||
balias ls_as_root 'sudo ls'
|
||||
expect test $status --to-be-true
|
||||
end
|
||||
end
|
||||
|
||||
spec.run $argv
|
|
@ -1,24 +0,0 @@
|
|||
set -l brew_paths /usr/local/bin /usr/bin /bin /usr/local/sbin /usr/sbin /sbin
|
||||
|
||||
# Append all existing brew paths to PATH
|
||||
set -l existing_brew_paths
|
||||
for brew_path in $brew_paths
|
||||
if test -d $brew_path
|
||||
set PATH $PATH $brew_path
|
||||
set existing_brew_paths $existing_brew_paths $brew_path
|
||||
end
|
||||
end
|
||||
|
||||
# Remove brew paths from tail to head that were not recently added
|
||||
set -l number_of_paths_to_ignore (math (count $PATH) - (count $existing_brew_paths))
|
||||
for i in (seq (count $PATH))[-1..1]
|
||||
if test $i -le $number_of_paths_to_ignore
|
||||
if contains $PATH[$i] $brew_paths
|
||||
set -e PATH[$i]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
set -e brew_paths
|
||||
set -e existing_brew_paths
|
||||
set -e existing_brew_paths_count
|
|
@ -1,63 +0,0 @@
|
|||
# These methods override the default calls to append `bundle exec` if this gem
|
||||
# is available within the context of bundler.
|
||||
#
|
||||
# You can add more bundled executables in your config.fish:
|
||||
#
|
||||
# set bundler_plugin_execs jekyll mustache
|
||||
#
|
||||
set -l execs annotate \
|
||||
cap \
|
||||
capify \
|
||||
cucumber \
|
||||
dashing \
|
||||
foreman \
|
||||
guard \
|
||||
kitchen \
|
||||
middleman \
|
||||
nanoc \
|
||||
puma \
|
||||
rackup \
|
||||
rainbows \
|
||||
rake \
|
||||
rspec \
|
||||
rubocop \
|
||||
ruby \
|
||||
shotgun \
|
||||
sidekiq \
|
||||
spec \
|
||||
spinach \
|
||||
spork \
|
||||
thin \
|
||||
thor \
|
||||
unicorn \
|
||||
unicorn_rails
|
||||
|
||||
if set -q bundler_plugin_execs
|
||||
set execs $execs $bundler_plugin_execs
|
||||
end
|
||||
|
||||
# Fish 2.1.1+ has support for --inherit-variable
|
||||
set -l do_eval (echo $FISH_VERSION | grep 2.1.1-)
|
||||
|
||||
for executable in $execs
|
||||
if test -z "$do_eval"
|
||||
eval "function $executable; __execute_as_bundler $executable \$argv; end"
|
||||
else
|
||||
function $executable --inherit-variable executable
|
||||
__execute_as_bundler $executable $argv
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function __execute_as_bundler
|
||||
if __is_a_bundled_executable $argv[1]
|
||||
command bundle exec $argv
|
||||
else
|
||||
eval command $argv
|
||||
end
|
||||
end
|
||||
|
||||
function __is_a_bundled_executable
|
||||
set -l bindir (command bundle exec ruby -e 'puts Gem.bindir')
|
||||
test -f "$bindir/$argv"
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
_prepend_path $HOME/.cask/bin
|
|
@ -1,9 +0,0 @@
|
|||
# Use ccache for building Android
|
||||
# See: https://source.android.com/source/initializing.html#setting-up-ccache
|
||||
set -gx USE_CCACHE 1
|
||||
|
||||
if test -n "$CCACHE_ROOT"
|
||||
_prepend_path $CCACHE_ROOT
|
||||
else
|
||||
_prepend_path /usr/lib/ccache/bin
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
## chruby plugin
|
||||
|
||||
Depends on `chruby-fish`: https://github.com/JeanMertz/chruby-fish
|
||||
|
||||
set `CHRUBY_AUTO_ENABLED` to `false` to disable auto loading Ruby versions on
|
||||
directory change.
|
||||
|
||||
set `CHRUBY_ROOT` to point to the root path of chruby. The path will be
|
||||
appended by `share/chruby/chruby.fish` and `share/chruby/auto.fish`.
|
|
@ -1,23 +0,0 @@
|
|||
#
|
||||
# Depends on `chruby-fish` (https://github.com/JeanMertz/chruby-fish)
|
||||
#
|
||||
# set `CHRUBY_AUTO_ENABLED` to `false` to disable auto loading Ruby versions on
|
||||
# directory change.
|
||||
#
|
||||
# set `CHRUBY_ROOT` to point to the root path of chruby. The path will be
|
||||
# appended by `share/chruby/chruby.fish` and `share/chruby/auto.fish`.
|
||||
#
|
||||
set -q CHRUBY_ROOT; or set CHRUBY_ROOT /usr/local
|
||||
|
||||
if test -f "$CHRUBY_ROOT/share/chruby/chruby.fish"
|
||||
. "$CHRUBY_ROOT/share/chruby/chruby.fish"
|
||||
else
|
||||
echo '`chruby` plugin loaded but chruby-fish not installed.' \
|
||||
'See: https://github.com/JeanMertz/chruby-fish'
|
||||
end
|
||||
|
||||
if test "$CHRUBY_AUTO_ENABLED" != "false" -a \
|
||||
-f "$CHRUBY_ROOT/share/chruby/auto.fish"
|
||||
|
||||
. "$CHRUBY_ROOT/share/chruby/auto.fish"
|
||||
end
|
|
@ -1,10 +0,0 @@
|
|||
# composer command
|
||||
function composer
|
||||
if test -e ./composer.phar # if there is composer in this path use local one
|
||||
./composer.phar $argv;
|
||||
else if test -n "$COMPOSER_BIN"
|
||||
eval "$COMPOSER_BIN" $argv;
|
||||
else
|
||||
echo "Please install composer.phar to your PATH. Or use \"composer_install\" to install Composer to current directory."
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
# add Composer's global binaries to PATH
|
||||
if test -z "$COMPOSER_BIN_PATH"
|
||||
set -gx COMPOSER_BIN_PATH $HOME/.composer/vendor/bin
|
||||
end
|
||||
set PATH $COMPOSER_BIN_PATH $PATH
|
||||
|
||||
# get composer path
|
||||
if test -z "$COMPOSER_BIN"
|
||||
if type "composer.phar" > /dev/null
|
||||
set -gx COMPOSER_BIN (which composer.phar)
|
||||
else if type "composer" > /dev/null
|
||||
set -gx COMPOSER_BIN (which composer)
|
||||
else
|
||||
echo "FAILED to find Composer! Please install composer.phar to your PATH."
|
||||
end
|
||||
end
|
|
@ -1,4 +0,0 @@
|
|||
# install composer in the current directory
|
||||
function composer_install
|
||||
curl -s https://getcomposer.org/installer | php
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
# time, cleanup pyc and running test, settings as first argument
|
||||
# e.g. djtest settings_dev
|
||||
function djtest
|
||||
set VERBOSE --verbosity=1
|
||||
find . -name "*.pyc" -delete
|
||||
|
||||
if set -q argv
|
||||
time python manage.py test $VERBOSE --settings=$argv
|
||||
else
|
||||
time python manage.py test $VERBOSE
|
||||
end
|
||||
end
|
|
@ -1,23 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Roman Inflianskas
|
||||
|
||||
Copyright (c) 2014 Paul Joannon (sprunge.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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -1,104 +0,0 @@
|
|||
#!/usr/bin/env fish
|
||||
# vim: ai ts=2 sw=2 et sts=2
|
||||
|
||||
|
||||
# Just a dpaste (https://github.com/bartTC/dpaste) wrapper for fish-shell
|
||||
# Roman Inflianskas (rominf) <infroma@gmail.com>
|
||||
# Based on fish-sprunge plugin:
|
||||
# Paul Joannon (paulloz) <paul.joannon@gmail.com>
|
||||
# https://github.com/Paulloz/fish-sprunge
|
||||
# Based on oh-my-zsh's sprunge plugin
|
||||
|
||||
|
||||
set __dpaste_expires_choises '(onetime|1|twotimes|2|hour|week|month|never)'
|
||||
|
||||
function __dpaste_set_defaults
|
||||
set -g __dpaste_url_dpaste_de 'https://dpaste.de/api/?format=url'
|
||||
set -g __dpaste_keyword_dpaste_de 'content'
|
||||
set -g __dpaste_url_sprunge_us 'http://sprunge.us/'
|
||||
set -g __dpaste_keyword_sprunge_us 'sprunge'
|
||||
|
||||
set -q dpaste_site; or set -g dpaste_site 'dpaste.de'
|
||||
set suffix (echo $dpaste_site | sed "s/\./_/g")
|
||||
|
||||
set -g __dpaste_keyword (eval 'echo $__dpaste_keyword_'$suffix)
|
||||
set -q __dpaste_keyword; or set -g __dpaste_keyword $__dpaste_keyword_dpaste_de
|
||||
set -g __dpaste_send_url (eval 'echo $__dpaste_url_'$suffix)
|
||||
set -q __dpaste_send_url; or set -g __dpaste_send_url $__dpaste_url_dpaste_de
|
||||
set -g __dpaste_eat_once 0
|
||||
end
|
||||
|
||||
function __dpaste_send
|
||||
function curl
|
||||
command curl --silent $argv
|
||||
end
|
||||
|
||||
curl -F "$__dpaste_keyword=<-" $__dpaste_send_url | read -l url
|
||||
if [ $__dpaste_eat_once = 1 ]
|
||||
curl $url >/dev/null
|
||||
end
|
||||
echo $url
|
||||
end
|
||||
|
||||
function __dpaste_parse_expires
|
||||
set expires_spec "-t $__dpaste_expires_choises"
|
||||
set expires (echo $argv | sed -E "s/.*$expires_spec.*/\1/")
|
||||
if [ -z (echo $expires | sed -E "s/$__dpaste_expires_choises//") ]
|
||||
echo $expires | grep -qE '(onetime|1)'; set -g __dpaste_eat_once (and echo 1; or echo 0)
|
||||
set expires (echo $expires | sed -E 's/(1|2|twotimes)/onetime/;s/hour/3600/;s/week/604800/;s/month/2592000/')
|
||||
set __dpaste_send_url "$__dpaste_send_url&expires=$expires"
|
||||
end
|
||||
echo $argv | sed -E "s/$expires_spec//" | xargs
|
||||
end
|
||||
|
||||
function __dpaste_help
|
||||
echo -e \
|
||||
"Usage:
|
||||
dpaste [-t EXPIRES] < README.md
|
||||
dpaste [-t EXPIRES] README.md
|
||||
cat README.md | dpaste [-t EXPIRES]
|
||||
dpaste [-t EXPIRES] \"I \<3 to paste\"
|
||||
|
||||
Options:
|
||||
-t EXPIRES set snippet expiration time: $__dpaste_expires_choises [default: month]
|
||||
|
||||
Configuration:
|
||||
You can use this plugin with other dpaste instances.
|
||||
If you have a dpaste instance on 'example.com' just insert those lines
|
||||
into your config.fish file:
|
||||
set __dpaste_url_example_com 'https://example.com/api/?format=url'
|
||||
set dpaste_site 'example.com'
|
||||
|
||||
You can even use this plugin with sprunge.us.
|
||||
Note, that sprunge.us doesn't support '-t' option.
|
||||
set dpaste_site 'sprunge.us'"
|
||||
end
|
||||
|
||||
function __dpaste_parse_help
|
||||
begin
|
||||
contains -- -h $argv
|
||||
or contains -- --help $argv
|
||||
end
|
||||
and __dpaste_help
|
||||
end
|
||||
|
||||
function dpaste
|
||||
__dpaste_set_defaults
|
||||
__dpaste_parse_help $argv
|
||||
or begin
|
||||
set argv (__dpaste_parse_expires $argv)
|
||||
if isatty
|
||||
if [ -n $argv ]
|
||||
if [ -f $argv ]
|
||||
cat $argv
|
||||
else
|
||||
echo $argv
|
||||
end | __dpaste_send
|
||||
else
|
||||
__dpaste_help
|
||||
end
|
||||
else
|
||||
__dpaste_send
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
set -l fish_tank /usr/local/share/fish-tank/tank.fish
|
||||
if not test -e $fish_tank
|
||||
echo 'error: fish-tank is required to run these tests (https://github.com/terlar/fish-tank)'
|
||||
exit 1
|
||||
end
|
||||
|
||||
source $fish_tank
|
|
@ -1,109 +0,0 @@
|
|||
#!/usr/bin/env fish
|
||||
# vim: ai ts=2 sw=2 et sts=2
|
||||
|
||||
|
||||
function echo_text
|
||||
set -g __test_text 'Hello, tests! I am just testing suite for oh-my-fish plugin: https://github.com/bpinto/oh-my-fish/pull/170'
|
||||
echo -e $__test_text
|
||||
end
|
||||
|
||||
function curl
|
||||
command curl --silent $argv
|
||||
end
|
||||
|
||||
function curl_and_check
|
||||
assert_equal $argv[2..-1] (curl $argv[1])
|
||||
end
|
||||
|
||||
function curl_and_fail
|
||||
assert_match '.*404 Not found.*' (curl $argv[1])
|
||||
end
|
||||
|
||||
function test_dpaste_system
|
||||
set url (eval $argv[1])/raw
|
||||
curl_and_check $url (echo_text)
|
||||
# now it shouldn't be available
|
||||
curl_and_fail $url
|
||||
end
|
||||
|
||||
function dpaste_setup
|
||||
set -g test_dir /tmp/dpaste_test
|
||||
set -g test_file $test_dir/file
|
||||
mkdir -p $test_dir
|
||||
pushd
|
||||
cd $test_dir
|
||||
echo_text > $test_file
|
||||
end
|
||||
|
||||
function dpaste_teardown
|
||||
rm -rf $test_dir
|
||||
popd
|
||||
end
|
||||
|
||||
function suite_dpaste
|
||||
|
||||
function setup
|
||||
set dpaste_site 'dpaste.de'
|
||||
__dpaste_set_defaults
|
||||
end
|
||||
|
||||
function test_dpaste_parse_expires
|
||||
assert_equal text (__dpaste_parse_expires text)
|
||||
assert_equal "https://dpaste.de/api/?format=url" $__dpaste_send_url
|
||||
end
|
||||
|
||||
function test_dpaste_parse_expires_1
|
||||
assert_equal text (__dpaste_parse_expires -t 1 text)
|
||||
assert_equal "https://dpaste.de/api/?format=url&expires=onetime" $__dpaste_send_url
|
||||
end
|
||||
|
||||
function test_dpaste_parse_expires_hour
|
||||
assert_equal text (__dpaste_parse_expires -t hour text)
|
||||
assert_equal "https://dpaste.de/api/?format=url&expires=3600" $__dpaste_send_url
|
||||
end
|
||||
|
||||
function test_dpaste_parse_expires_never
|
||||
assert_equal text (__dpaste_parse_expires -t never text)
|
||||
assert_equal "https://dpaste.de/api/?format=url&expires=never" $__dpaste_send_url
|
||||
end
|
||||
|
||||
function test_dpaste_system_file_redirect
|
||||
function dpaste_file_redirect
|
||||
dpaste -t onetime < /tmp/dpaste_test/file
|
||||
end
|
||||
test_dpaste_system dpaste_file_redirect
|
||||
end
|
||||
|
||||
function test_dpaste_system_file
|
||||
function dpaste_file
|
||||
dpaste -t onetime /tmp/dpaste_test/file
|
||||
end
|
||||
test_dpaste_system dpaste_file
|
||||
end
|
||||
|
||||
function test_dpaste_system_stdin
|
||||
function dpaste_stdin
|
||||
echo_text | dpaste -t onetime
|
||||
end
|
||||
test_dpaste_system dpaste_stdin
|
||||
end
|
||||
|
||||
function test_dpaste_system_text
|
||||
function dpaste_text
|
||||
dpaste -t onetime "$__test_text"
|
||||
end
|
||||
test_dpaste_system dpaste_text
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
if not set -q tank_running
|
||||
source (dirname (status -f))/helper.fish
|
||||
set -g __dpaste_expires_choises
|
||||
source (dirname (status -f))/../dpaste.fish
|
||||
|
||||
dpaste_setup
|
||||
tank_run
|
||||
dpaste_teardown
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
### Main program
|
||||
|
||||
if test -d (/usr/libexec/java_home)
|
||||
set -gx JAVA_HOME (/usr/libexec/java_home)
|
||||
end
|
||||
|
||||
if test (/bin/ls $HOME/.ec2/pk-*.pem | /usr/bin/head -1)
|
||||
set -gx EC2_PRIVATE_KEY (/bin/ls $HOME/.ec2/pk-*.pem | /usr/bin/head -1)
|
||||
end
|
||||
|
||||
if test (/bin/ls $HOME/.ec2/cert-*.pem | /usr/bin/head -1)
|
||||
set -gx EC2_CERT (/bin/ls $HOME/.ec2/cert-*.pem | /usr/bin/head -1)
|
||||
end
|
||||
|
||||
if test -d /usr/local/Library/LinkedKegs/ec2-api-tools/jars
|
||||
set -gx EC2_HOME /usr/local/Library/LinkedKegs/ec2-api-tools/jars
|
||||
end
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
# Emacs Plugin
|
||||
|
||||
This plugin replicates the functionality of the [emacs](https://www.gnu.org/software/emacs/) plugin for [oh-my-zsh](http://ohmyz.sh/).
|
||||
It is essentially a wrapper around the very useful [emacs daemon](http://www.emacswiki.org/emacs/EmacsAsDaemon) capability.
|
||||
|
||||
Below is an extract from the original plugin source file:
|
||||
|
||||
"Emacs 23 daemon capability is a killing feature.
|
||||
One emacs process handles all your frames whether
|
||||
you use a frame opened in a terminal via a ssh connection or X frames
|
||||
opened on the same host.
|
||||
Benefits are multiple
|
||||
|
||||
* You don't have the cost of starting Emacs all the time anymore
|
||||
* Opening a file is as fast as Emacs does not have anything else to do.
|
||||
* You can share opened buffered across opened frames.
|
||||
* Configuration changes made at runtime are applied to all frames."
|
||||
|
||||
|
||||
### Usage
|
||||
|
||||
To use this plugin add `emacs` to `fish_plugins` in you fish config file:
|
||||
|
||||
```bash
|
||||
set fish_plugins emacs
|
||||
```
|
||||
|
||||
### Requirements
|
||||
|
||||
Emacs 23 or later is required for this plugin.
|
|
@ -1,39 +0,0 @@
|
|||
function __major_version
|
||||
if test -n "$argv"
|
||||
set -l full_metadata (eval $argv --version)
|
||||
set -l full_version (echo $full_metadata | grep -o "[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+")
|
||||
set -l major_version (echo $full_version | sed "s/\..*//")
|
||||
end
|
||||
|
||||
echo $major_version
|
||||
end
|
||||
|
||||
function __set_editor
|
||||
if not set -q EDITOR
|
||||
set -gx EDITOR emacs
|
||||
end
|
||||
end
|
||||
|
||||
function __add_functions_to_path
|
||||
set emacs_functions $fish_path/plugins/emacs/functions
|
||||
set fish_function_path $emacs_functions $fish_function_path
|
||||
end
|
||||
|
||||
if not set -q __emacs
|
||||
set __emacs (which emacs)
|
||||
end
|
||||
if not set -q __emacs_version
|
||||
set __emacs_version (__major_version $__emacs)
|
||||
end
|
||||
|
||||
if test "$__emacs_version" -gt 23
|
||||
__set_editor
|
||||
__add_functions_to_path
|
||||
end
|
||||
|
||||
set -e emacs
|
||||
set -e emacs_version
|
||||
functions -e __major_version
|
||||
functions -e __plugins_path
|
||||
functions -e __set_editor
|
||||
functions -e __add_functions_to_path
|
|
@ -1,3 +0,0 @@
|
|||
function __kill_emacs
|
||||
emacsclient --alternate-editor '' --eval '(kill-emacs)' 2>/dev/null
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
function __launch_emacs
|
||||
set -l x (emacsclient --alternate-editor '' --eval '(x-display-list)' 2>/dev/null)
|
||||
|
||||
if test -z "$x" -o "$x" = nil
|
||||
emacsclient $argv --alternate-editor '' --create-frame
|
||||
else
|
||||
emacsclient $argv --alternate-editor ''
|
||||
end
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function e
|
||||
__launch_emacs $argv --no-wait
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function ec
|
||||
__launch_emacs $argv --create-frame --no-wait
|
||||
end
|
|
@ -1,11 +0,0 @@
|
|||
function ecd
|
||||
set -l cmd '(let ((buf-name (buffer-file-name (window-buffer))))
|
||||
(if buf-name (file-name-directory buf-name)))'
|
||||
set -l dir (__launch_emacs --eval $cmd | tr -d '\"')
|
||||
|
||||
if test -n "$dir"
|
||||
echo $dir
|
||||
else
|
||||
echo 'cannot deduce current buffer filename.' >/dev/stderr
|
||||
end
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function eeval
|
||||
__launch_emacs --eval $argv
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
function efile
|
||||
set -l cmd '(buffer-file-name (window-buffer))'
|
||||
|
||||
__launch_emacs --eval $cmd | tr -d '\"'
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function eframe
|
||||
__launch_emacs $argv --create-frame --no-wait
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function ek
|
||||
__kill_emacs
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function emacs
|
||||
__launch_emacs $argv --no-wait
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function emasc
|
||||
__launch_emacs $argv --no-wait
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function emcas
|
||||
__launch_emacs $argv --no-wait
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
function et
|
||||
__launch_emacs $argv --tty
|
||||
end
|
|
@ -1,118 +0,0 @@
|
|||
import plugins/fish-spec
|
||||
|
||||
|
||||
function describe_emacs
|
||||
|
||||
function before_all
|
||||
set -g __emacs_current_editor $EDITOR
|
||||
set -g __emacs_load_file $fish_path/plugins/emacs/emacs.load
|
||||
set -g __emacs_functions e ec ek et ecd eeval efile eframe emacs emasc emcas
|
||||
end
|
||||
|
||||
function before_each
|
||||
set -e EDITOR
|
||||
set -g __emacs '/bin/emacs'
|
||||
set -g __emacs_version 25
|
||||
end
|
||||
|
||||
function it_sets_editor_on_load
|
||||
load_emacs_plugin
|
||||
|
||||
expect $EDITOR --to-equal "emacs"
|
||||
end
|
||||
|
||||
function it_does_not_set_editor_when_it_is_already_set
|
||||
set EDITOR 'vim'
|
||||
|
||||
load_emacs_plugin
|
||||
|
||||
expect $EDITOR --to-equal "vim"
|
||||
end
|
||||
|
||||
function it_does_not_set_editor_when_emacs_is_not_found
|
||||
emacs_is_not_found
|
||||
|
||||
load_emacs_plugin
|
||||
|
||||
expect "$EDITOR" --to-equal ""
|
||||
end
|
||||
|
||||
function it_does_not_set_editor_when_emacs_version_is_lower_than_23
|
||||
set __emacs_version 22
|
||||
|
||||
load_emacs_plugin
|
||||
|
||||
expect "$EDITOR" --to-equal ""
|
||||
end
|
||||
|
||||
function it_adds_functions_to_fish_function_path
|
||||
load_emacs_plugin
|
||||
|
||||
expect (functions) --to-contain-all $__emacs_functions
|
||||
end
|
||||
|
||||
function it_has_a_test_helper_that_removes_emacs_functions
|
||||
load_emacs_plugin
|
||||
|
||||
expect (functions) --to-contain-all $__emacs_functions
|
||||
|
||||
remove_emacs_functions
|
||||
|
||||
expect (functions) --to-not-contain-all $__emacs_functions
|
||||
end
|
||||
|
||||
|
||||
function it_does_not_add_functions_when_emacs_is_not_found
|
||||
remove_emacs_functions
|
||||
emacs_is_not_found
|
||||
|
||||
load_emacs_plugin
|
||||
|
||||
expect (functions) --to-not-contain-all $__emacs_functions
|
||||
end
|
||||
|
||||
function it_does_not_add_functions_when_emacs_version_is_lower_than_23
|
||||
set __emacs_version 22
|
||||
|
||||
expect (functions) --to-not-contain-all $__emacs_functions
|
||||
|
||||
load_emacs_plugin
|
||||
|
||||
expect (functions) --to-not-contain-all $__emacs_functions
|
||||
end
|
||||
|
||||
|
||||
function emacs_is_not_found
|
||||
set __emacs ""
|
||||
set __emacs_version ""
|
||||
end
|
||||
|
||||
function load_emacs_plugin
|
||||
source $__emacs_load_file
|
||||
end
|
||||
|
||||
function remove_emacs_functions
|
||||
for path in $fish_function_path
|
||||
set match (echo $path | grep emacs)
|
||||
if test -z "$match"
|
||||
set -g __new_fish_function_path $__new_fish_function_path $path
|
||||
end
|
||||
end
|
||||
|
||||
set fish_function_path $__new_fish_function_path
|
||||
set -e __new_fish_function_path
|
||||
end
|
||||
|
||||
function after_all
|
||||
set EDITOR $__emacs_current_editor
|
||||
|
||||
set -e __emacs
|
||||
set -e __emacs_version
|
||||
set -e __emacs_load_file
|
||||
set -e __emacs_functions
|
||||
set -e __emacs_current_editor
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
spec.run $argv
|
|
@ -1,89 +0,0 @@
|
|||
# ------------------------------------------------------------------------------
|
||||
# FILE: emoji-clock.plugin.zsh
|
||||
# DESCRIPTION: The current time with half hour accuracy as an emoji symbol.
|
||||
# Inspired by Andre Torrez' "Put A Burger In Your Shell"
|
||||
# http://notes.torrez.org/2013/04/put-a-burger-in-your-shell.html
|
||||
# AUTHOR: Alexis Hildebrandt (afh[at]surryhill.net) ported to fish by Erik Kallen
|
||||
# VERSION: 1.0.0
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
function emoji-clock
|
||||
set hour (date '+%I')
|
||||
set minutes (date '+%M')
|
||||
switch $hour
|
||||
case 01
|
||||
if test $minutes -ge 30
|
||||
set clock "🕜"
|
||||
else
|
||||
set clock "🕐"
|
||||
end
|
||||
case 02
|
||||
if test $minutes -ge 30
|
||||
set clock "🕝"
|
||||
else
|
||||
set clock "🕑"
|
||||
end
|
||||
case 03
|
||||
if test $minutes -ge 30
|
||||
set clock "🕞"
|
||||
else
|
||||
set clock "🕒"
|
||||
end
|
||||
case 04
|
||||
if test $minutes -ge 30
|
||||
set clock "🕟"
|
||||
else
|
||||
set clock "🕓"
|
||||
end
|
||||
case 05
|
||||
if test $minutes -ge 30
|
||||
set clock "🕠"
|
||||
else
|
||||
set clock "🕔"
|
||||
end
|
||||
case 06
|
||||
if test $minutes -ge 30
|
||||
set clock "🕡"
|
||||
else
|
||||
set clock "🕕"
|
||||
end
|
||||
case 07
|
||||
if test $minutes -ge 30
|
||||
set clock "🕢"
|
||||
else
|
||||
set clock "🕖"
|
||||
end
|
||||
case 08
|
||||
if test $minutes -ge 30
|
||||
set clock "🕣"
|
||||
else
|
||||
set clock "🕗"
|
||||
end
|
||||
case 09
|
||||
if test $minutes -ge 30
|
||||
set clock "🕤"
|
||||
else
|
||||
set clock "🕘"
|
||||
end
|
||||
case 10
|
||||
if test $minutes -ge 30
|
||||
set clock "🕥"
|
||||
else
|
||||
set clock "🕙"
|
||||
end
|
||||
case 11
|
||||
if test $minutes -ge 30
|
||||
set clock "🕦"
|
||||
else
|
||||
set clock "🕚"
|
||||
end
|
||||
case 12
|
||||
if test $minutes -ge 30
|
||||
set clock "🕧"
|
||||
else
|
||||
set clock "🕛"
|
||||
end
|
||||
case '*' set clock "⌛"
|
||||
end
|
||||
echo $clock
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
function export
|
||||
set var1 (echo $argv | cut -f1 -d=)
|
||||
set var2 (echo $argv | cut -f2 -d=)
|
||||
set -x -g $var1 $var2
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
# Taken from: https://github.com/dideler/dotfiles/blob/master/functions/extract.fish
|
||||
|
||||
function extract --description "Expand or extract bundled & compressed files"
|
||||
set --local ext (echo $argv[1] | awk -F. '{print $NF}')
|
||||
switch $ext
|
||||
case tar # non-compressed, just bundled
|
||||
tar -xvf $argv[1]
|
||||
case gz
|
||||
if test (echo $argv[1] | awk -F. '{print $(NF-1)}') = tar # tar bundle compressed with gzip
|
||||
tar -zxvf $argv[1]
|
||||
else # single gzip
|
||||
gunzip $argv[1]
|
||||
end
|
||||
case tgz # same as tar.gz
|
||||
tar -zxvf $argv[1]
|
||||
case bz2 # tar compressed with bzip2
|
||||
tar -jxvf $argv[1]
|
||||
case rar
|
||||
unrar x $argv[1]
|
||||
case zip
|
||||
unzip $argv[1]
|
||||
case '*'
|
||||
echo "unknown extension"
|
||||
end
|
||||
end
|
|
@ -1,4 +0,0 @@
|
|||
### Main program
|
||||
if test -d /usr/local/share/fry/fry.fish
|
||||
. /usr/local/share/fry/fry.fish
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
# gem
|
||||
Ruby gem support for fish.
|
||||
|
||||
## Install
|
||||
Add `gem` to your list of fish plugins in your `config.fish`.
|
||||
|
||||
Example:
|
||||
|
||||
set fish_plugins gem bundler
|
||||
|
||||
## Configuration
|
||||
Set `GEM_ROOT` in your `config.fish`.
|
||||
|
||||
Example:
|
||||
|
||||
set GEM_ROOT ~/.gem/ruby/2.1.0
|
|
@ -1,4 +0,0 @@
|
|||
if test -n "$GEM_ROOT"
|
||||
set -gx GEM_HOME $GEM_ROOT
|
||||
_prepend_path $GEM_ROOT/bin
|
||||
end
|
|
@ -1,110 +0,0 @@
|
|||
# getopts
|
||||
> friendly [`getopts`](http://en.wikipedia.org/wiki/Getopts) for [fish](https://fishshell.com) :fish:
|
||||
|
||||
## Usage
|
||||
|
||||
```fish
|
||||
Add `getopts` to your `$fish_plugins` or import directly into your library via `import plugins/getopts`.
|
||||
```
|
||||
|
||||
## Premise
|
||||
Every utility / function needs to handle arguments. What usually happens is that every function does all the grunt work to parse `$argv` itself, and while some patterns do tend to recur, it's different almost every time. Enter fish `getopts`.
|
||||
|
||||
## Synopsis
|
||||
`getopts <option string> [ARGV...]`
|
||||
|
||||
## Options
|
||||
#### `<option string> [:][<letter>][[:]<word>[:[^]]]`
|
||||
|
||||
A string containing the option characters recognized by the utility calling `getopts`. If a `<letter>` or `<word>` ends in `:`, the option is expected to have an argument, which may be supplied separately or next to the option without spaces in the same string.
|
||||
|
||||
To indicate long options: `<letter>:<word>` and `<word>` are both valid option strings that will attempt to match `-<letter>` and `--<word>`.
|
||||
|
||||
To indicate _only_ short options, do not specify a `:<word>` after `<letter>`. For example, `a b` will match `-a` or `-b`.
|
||||
|
||||
To indicate optional arguments, use a `^` character after a `:` at the end of the option in the option string. For example `<letter>:^` and `<letter>:<word>:^` are both valid. Optional arguments should be supplied in the same string as the option and without spaces, e.g, `-<letter>value` will correctly assign `value` as the argument to the the option `<letter>`, but `-<letter>` value, will parse `value` as the next argument in `<ARGV>`.
|
||||
|
||||
To specify optional arguments using the option's long form, use a `=` character after the option: `--<word>=value`.
|
||||
|
||||
Use a `:` at the beginning of the option string to enable strict mode. If enabled, `getopts` will exit with a status __> 0__ if or when an unknown option is found. See [Diagnostics](#diagnostics).
|
||||
|
||||
#### `<ARGV>`
|
||||
|
||||
List of options and operands to parse. `getopts` prints any matched options as well as available argument separated by a \n to stdout and returns with a status of __0__ if there are still arguments; else returns with a status __> 0__ if the end of the options is reached or an error occurs. See [Diagnostics](#diagnostics).
|
||||
|
||||
#### Summary
|
||||
|
||||
| Option String | Argument | Short Style | Long Style |
|
||||
|:---------------:|:--------------:|------------------|:--------------------:|
|
||||
`"q:qqq:"` | Required | `-q1` `-q 1` | `--qqq 1` |
|
||||
`"q:qqq:^"` | Optional | `-q1` | `--qqq=3` |
|
||||
|
||||
|
||||
## Description
|
||||
`getopts` obtains options and their arguments from a list of parameters that, as indicated by <option string>, are single letters preceded by a `-` or words preceded by `--` and possibly followed by an argument value.
|
||||
|
||||
fish `getopts` follows the specifications described in the [Utility Syntax Guidelines](http://pubs.opengroup.org/onlinepubs/7908799/xbd/utilconv.html). The following is a summary of the features:
|
||||
|
||||
+ Short options; single letters preceded by `-`, and long options; words preceded by `--`, are both supported.
|
||||
|
||||
+ Single letters may be grouped. `-abc` → `-a -b -c`
|
||||
|
||||
+ Options required to take an argument can specify the argument either in the same string as the option or separated from the by a space. (1) `-a argument`, (2) `-aargument`
|
||||
|
||||
+ Options that can take an argument optionally shall specify the argument in the same string as the option argument if in short option style: `-aargument`, or separated by a `=` if in long form: `--long-form=argument`. If a blank space is used, the following argument will be treated independently.
|
||||
|
||||
+ Options can appear multiple times in the same argument list. `getopts` will print every match sequentally on each call, and should default to the short form of the option if available.
|
||||
|
||||
+ The option delimiter `:` and optional argument character `^` shall not be used as an option.
|
||||
|
||||
+ `getopts` will return the remaining operands when the end of the options is reached, i.e, a `--` argument that is not an option is found, or an argument that does not begin with `-` is found.
|
||||
|
||||
## Environment Variables
|
||||
The following environment variables are used internally by `getopts`. These variables are erased from memory when the function returns 1.
|
||||
|
||||
+ `__getopts_optstr` _Whitespace trimmed option string._
|
||||
|
||||
+ `__getopts_argv` _Preprocessed copy of arguments._
|
||||
|
||||
+ `__getopts_index` _Index of the next argument to handle._
|
||||
|
||||
+ `__getopts_required` _List of options with required arguments._
|
||||
|
||||
+ `__getopts_optional` _List of options with optional arguments._
|
||||
|
||||
|
||||
## <a name="diagnostics"></a>Diagnostics
|
||||
Possible exit status values are:
|
||||
|
||||
+ __0__: An argument formed like an option was found. This causes getopts to print the option short-style and its argument if avaiable. If strict-mode is enabled setting the first character of the option to `:`, an unknown option will cause `getopts` to fail. See below.
|
||||
|
||||
+ __1__: The end of the options was reached. Remaining operands are also sent to stdout.
|
||||
|
||||
+ __2__: An option argument was missing.
|
||||
|
||||
+ __3__: An unknown option was found. Only if strict-mode is enabled.
|
||||
|
||||
## Examples
|
||||
```fish
|
||||
function my_utility
|
||||
while set optarg (getopts "l:long x: o:optional:^" $argv)
|
||||
switch $optarg[1]
|
||||
case l
|
||||
echo handle `-l --long`
|
||||
case x
|
||||
echo handle `-x` w/ argument `$optarg[2]`
|
||||
case o
|
||||
echo handle `-o --optional` w/ optional argument `$optarg[2]`
|
||||
case \*
|
||||
echo unknown option `$optarg[1]`
|
||||
end
|
||||
end
|
||||
echo -n operands: "`$optarg`"
|
||||
end
|
||||
```
|
||||
|
||||
## Links
|
||||
+ [UNIX Utility Conventions](http://pubs.opengroup.org/onlinepubs/7908799/xbd/utilconv.html)
|
||||
|
||||
## License
|
||||
[MIT](http://opensource.org/licenses/MIT) © [Jorge Bucaran](http://bucaran.me)
|
|
@ -1,409 +0,0 @@
|
|||
# NAME
|
||||
# getopts -- getopts for fish
|
||||
#
|
||||
# SYNOPSIS
|
||||
# getopts <option string> [ARGV...]
|
||||
#
|
||||
# OPTIONS
|
||||
# <option string> [:][<letter>][[:]<word>[:[^]]]
|
||||
#
|
||||
# A string containing the option characters recognized by the utility
|
||||
# calling getopts. If a <letter> or <word> ends in `:`, the option is
|
||||
# expected to have an argument, which may be supplied separately or
|
||||
# next to the option without spaces in the same string.
|
||||
#
|
||||
# To indicate long options: <letter>:<word> and <word> are both valid
|
||||
# option strings that will attempt to match -<letter> and --<word>.
|
||||
#
|
||||
# For only short options, do not specify a :<word> after <letter>.
|
||||
# For example, `a b` will match `-a` and/or `-b`.
|
||||
#
|
||||
# To indicate optional arguments, use a `^` character after a `:` at
|
||||
# the end of the option in the option string. For example <letter>:^
|
||||
# and <letter>:<word>:^ are both valid. Optional arguments should be
|
||||
# supplied in the same string as the option and without spaces, e.g,
|
||||
# -<letter>value will correctly assign `value` as the argument to the
|
||||
# the option <letter>, but -<letter> value, will parse `value` as the
|
||||
# next argument in <argv>.
|
||||
#
|
||||
# To specify optional arguments using the option's long form, use a
|
||||
# `=` character after the option: --<word>=value.
|
||||
#
|
||||
# Use a `:` at the beginning of the option string to enable strict
|
||||
# mode. If enabled, getopts will exit with a status > 0 if or when
|
||||
# an unknown option is found. See DIAGNOSTICS.
|
||||
#
|
||||
# <ARGV>
|
||||
#
|
||||
# List of options and operands to parse. getopts prints any matched
|
||||
# options as well as available argument separated by a \n to stdout
|
||||
# and returns with a status of 0 if there are still arguments; else
|
||||
# returns with a status > 0 if the end of the options is reached or
|
||||
# an error occurs. See DIAGNOSTICS.
|
||||
#
|
||||
# DESCRIPTION
|
||||
# getopts obtains options and their arguments from a list of parameters
|
||||
# that, as indicated by <option string>, are single letters preceded by
|
||||
# a - or words preceded by -- and possibly followed by an argument value.
|
||||
#
|
||||
# fish getopts follows the specifications described in the Utility Syntax
|
||||
# Guidelines (see LINKS); the following is a summary of the features:
|
||||
#
|
||||
# + Short options; single letters preceded by -, and long options;
|
||||
# words preceded by --, are both supported.
|
||||
#
|
||||
# + Single letters may be grouped. -abc → -a -b -c
|
||||
#
|
||||
# + Options required to take an argument can specify the argument
|
||||
# either in the same string as the option or separated from the
|
||||
# by a space. (1) -a argument, (2) -aargument
|
||||
#
|
||||
# + Options that can take an argument optionally shall specify the
|
||||
# argument in the same string as the option argument if in short
|
||||
# option style: -aargument, or separated by a = if in long form:
|
||||
# --long-form=argument. If a blank space is used, the following
|
||||
# argument will be treated independently.
|
||||
#
|
||||
# + Options can appear multiple times in the same argument list.
|
||||
# getopts will print every match sequentally on each call, and
|
||||
# should default to the short form of the option if available.
|
||||
#
|
||||
# + The option delimiter `:` and optional argument character `^`
|
||||
# shall not be used as an option.
|
||||
#
|
||||
# + getopts will return the remaining operands when the end of the
|
||||
# options is reached, i.e, a `--` argument that is not an option
|
||||
# is found, or an argument that does not begin with `-` is found.
|
||||
#
|
||||
# ENVIRONMENT VARIABLES
|
||||
# The following environment variables are used internally by getopts.
|
||||
# These variables are erased from memory when the functions returns 1.
|
||||
#
|
||||
# + __getopts_optstr Whitespace trimmed option string.
|
||||
# + __getopts_argv Preprocessed copy of arguments.
|
||||
# + __getopts_index Index of the next argument to handle.
|
||||
# + __getopts_required List of options with required arguments.
|
||||
# + __getopts_optional List of options with optional arguments.
|
||||
#
|
||||
# DIAGNOSTICS
|
||||
# Possible exit status values are:
|
||||
#
|
||||
# 0 An argument formed like an option was found. This causes getopts
|
||||
# to print the option short-style and its argument if avaiable. If
|
||||
# strict-mode is enabled setting the first character of the option
|
||||
# to `:`, an unknown option will cause getopts to fail. See below.
|
||||
#
|
||||
# 1 The end of the options was reached. Remaining operands are also
|
||||
# sent to stdout.
|
||||
#
|
||||
# 2 An option argument was missing.
|
||||
#
|
||||
# 3 An unknown option was found. Only if strict-mode is enabled.
|
||||
#
|
||||
# EXAMPLES
|
||||
# function my_utility
|
||||
# while set optarg (getopts "l:long x: o:optional:^" $argv)
|
||||
# switch $optarg[1]
|
||||
# case l
|
||||
# echo handle `-l --long`
|
||||
# case x
|
||||
# echo handle `-x` w/ argument `$optarg[2]`
|
||||
# case o
|
||||
# echo handle `-o --optional` w/ optional argument `$optarg[2]`
|
||||
# case \*
|
||||
# echo unknown option `$optarg[1]`
|
||||
# end
|
||||
# end
|
||||
# echo -n operands: "`$optarg`"
|
||||
# end
|
||||
#
|
||||
# LINKS
|
||||
# UNIX Utility Conventions
|
||||
# → http://pubs.opengroup.org/onlinepubs/7908799/xbd/utilconv.html
|
||||
#
|
||||
# AUTHORS
|
||||
# Jorge Bucaran <jbucaran@me.com>
|
||||
#/
|
||||
function getopts
|
||||
# Currently supported return success/error conditions.
|
||||
set -l __CONTINUE 0
|
||||
set -l __END_OF_OPTIONS 1
|
||||
set -l __OPTION_ARGUMENT_EXPECTED 2
|
||||
set -l __UNKNOWN_OPTION_FOUND 3
|
||||
|
||||
# Self-destroying global variable cleanup utility.
|
||||
# Should be called before returning 1.
|
||||
function __getopts_cleanup
|
||||
set -e __getopts_optstr
|
||||
set -e __getopts_argv
|
||||
set -e __getopts_index
|
||||
set -e __getopts_required
|
||||
set -e __getopts_optional
|
||||
set -e __getopts_strict_mode
|
||||
functions -e __getopts_increase_index
|
||||
end
|
||||
|
||||
function __getopts_increase_index
|
||||
set __getopts_index (math $__getopts_index + 1)
|
||||
end
|
||||
|
||||
# Options string pre-processing.
|
||||
if not set -q __getopts_optstr
|
||||
set -g __getopts_optstr $argv[1]
|
||||
set -e argv[1]
|
||||
|
||||
# Trim option string and collect required / optional options.
|
||||
if [ -n "$__getopts_optstr" ]
|
||||
set __getopts_optstr (printf $__getopts_optstr | tr -s '[:space:]' \n)
|
||||
|
||||
# Setting the first token of the option string to `:` enables
|
||||
# strict mode. This causes getopts to abort the process if an
|
||||
# unknown option is found.
|
||||
set -l first_token (printf $__getopts_optstr | head -c1)
|
||||
|
||||
if [ : = "$first_token" ]
|
||||
set -g __getopts_strict_mode --true
|
||||
|
||||
# We can safely remove the `:` character now.
|
||||
set __getopts_optstr[1] (printf $__getopts_optstr[1] | cut -c2-)
|
||||
end
|
||||
|
||||
# Collect options with optional and required option-arguments.
|
||||
function __getopts_collect_optargs
|
||||
for string in (printf "%s\n" $__getopts_optstr)
|
||||
set -l token (printf $string | tail -c1)
|
||||
set -l split_string (printf "%s\n" $string | tr : \n)
|
||||
|
||||
# Erase last to make sure not to append `^` token.
|
||||
switch $token
|
||||
case :
|
||||
set -g __getopts_required $__getopts_required $split_string
|
||||
set -e __getopts_required[-1]
|
||||
case \^
|
||||
set -g __getopts_optional $__getopts_optional $split_string
|
||||
set -e __getopts_optional[-1]
|
||||
end
|
||||
end
|
||||
functions -e __getopts_collect_optargs
|
||||
end
|
||||
|
||||
__getopts_collect_optargs
|
||||
end
|
||||
end
|
||||
|
||||
# Sanitize arguments. Break up flags: -abc → -a -b -c, but skip optional
|
||||
# arguments. If -w is a flag that can take an optional argument, -abw123
|
||||
# should be parsed to → -a -b -w 123.
|
||||
if not set -q __getopts_argv
|
||||
function __getopts_sanitize_argv
|
||||
for token in $argv
|
||||
switch $token
|
||||
case --\* # Skip!
|
||||
case -\*
|
||||
# Split each token into single characters with `.`
|
||||
for char in (printf "%s" $token | cut -c2- | grep --only-matching .)
|
||||
# Do not split short option characters if this option can
|
||||
# take optional required arguments.
|
||||
if [ -z "$suspend_break" ]
|
||||
printf "-%s\n" $char
|
||||
else
|
||||
printf "%s" $char
|
||||
end
|
||||
|
||||
# Suspend option break-up if the current option is either
|
||||
# a required or an optional option type.
|
||||
contains -- $char $__getopts_required $__getopts_optional
|
||||
and set suspend_break --true
|
||||
|
||||
set last_char $char
|
||||
end
|
||||
|
||||
# Break options if we were in suspend mode and reset flag.
|
||||
# This makes sure to add a blank space if no argument was
|
||||
# specified for the optional option-argument, but not for
|
||||
# the required option-argument.
|
||||
if [ -n "$suspend_break" ]
|
||||
not contains -- $last_char $__getopts_required
|
||||
and printf "\n"
|
||||
set suspend_break ""
|
||||
end
|
||||
continue
|
||||
end
|
||||
|
||||
printf "%s\n" $token
|
||||
end
|
||||
functions -e __getopts_sanitize_argv
|
||||
end
|
||||
set -g __getopts_argv (__getopts_sanitize_argv $argv)
|
||||
end
|
||||
|
||||
# Always use our preprocessed argument list.
|
||||
set argv $__getopts_argv
|
||||
|
||||
if not set -q __getopts_index
|
||||
set -g __getopts_index 1
|
||||
end
|
||||
|
||||
# Handle next argument as indicated by the current index.
|
||||
if set -q argv[$__getopts_index]
|
||||
set -l option $argv[$__getopts_index]
|
||||
|
||||
# Potential matches for $option are: (1) end of arguments `--`,
|
||||
# (2) long/short options --* or -* or (3) begin of operands, if
|
||||
# (1) and (2) fail.
|
||||
switch $option
|
||||
# End of arguments. Assume everything from this point are operands.
|
||||
case --
|
||||
set -e argv[1..$__getopts_index]
|
||||
printf "%s\n" $argv
|
||||
__getopts_cleanup
|
||||
return $__END_OF_OPTIONS
|
||||
|
||||
# Looks like we have a well-formed long/short option. Parse.
|
||||
case --\* -\*
|
||||
# It will be useful later to know if the current option is in long
|
||||
# style. Notice we add a leading blank, because cut fails when the
|
||||
# first character is a dash `-`.
|
||||
set -e is_long_option
|
||||
test (printf " "$option | cut -c2-3) = "--"
|
||||
and set -l is_long_option
|
||||
|
||||
# Trim leading dashes and prepare to match with valid options.
|
||||
set option (printf "%s" $option | sed 's/^-*//g')
|
||||
|
||||
for substring in $__getopts_optstr
|
||||
# Split up by token separator `:`. The resulting list contains
|
||||
# all valid options, both in short and long style.
|
||||
set -l tokens (printf $substring | tr : \n)
|
||||
|
||||
# Start last to first to avoid mistaking long w/ short options.
|
||||
for index in (seq (count $tokens) -1 1)
|
||||
set -l last_token (printf $substring | tail -c1)
|
||||
|
||||
# Find options with optional argument in long-style and
|
||||
# try to split by required delimiter `=`
|
||||
|
||||
# Note: Optional values shall be separated from options in
|
||||
# long style by an equals sign. See documentation.
|
||||
|
||||
if [ $last_token = \^ ]
|
||||
if set -q is_long_option
|
||||
set -l option_value (printf "%s" $option | tr = \n)
|
||||
|
||||
if set -q option_value[2]
|
||||
# Check if it is a valid option match.
|
||||
if [ $option_value[1] = $tokens[$index] ]
|
||||
printf "%s\n" $tokens[1]
|
||||
printf $option_value[2]
|
||||
|
||||
__getopts_increase_index
|
||||
return $__CONTINUE
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# We are already inside a possible short/long option match.
|
||||
# Option is the argument in __getopts_argv[__getopts_index]
|
||||
# The following compares option against each valid argument
|
||||
# in the option string __getopts_optstr. If no match can be
|
||||
# found, print the argument after the loop.
|
||||
|
||||
switch $option
|
||||
case $tokens[$index]
|
||||
# Success. Send first token to stdout to make sure short
|
||||
# options, if available, always get the highest priority.
|
||||
printf "%s\n" $tokens[1]
|
||||
|
||||
switch $last_token
|
||||
# At this point, both required and optional arguments
|
||||
# look the same to the parser, so we match last_token
|
||||
# to either `:` required or `^` optional tokens. This
|
||||
# is the result of preprocessing __getopts_argv.
|
||||
|
||||
case : \^
|
||||
# Find options with optional argument in long-style.
|
||||
if [ $last_token = \^ ]
|
||||
if set -q is_long_option
|
||||
|
||||
# An optional argument in long-style here means it
|
||||
# didn't split by = in previous checks, so we can
|
||||
# handle it as a missing argument option and exit.
|
||||
|
||||
# Print any non-empty list character.
|
||||
printf "\n"
|
||||
__getopts_increase_index
|
||||
return $__CONTINUE
|
||||
end
|
||||
end
|
||||
|
||||
# If we reach this, we are either handling a required
|
||||
# option or an optional in short-style form. Both are
|
||||
# seen by the parser the same after preprocessing.
|
||||
|
||||
# For example:
|
||||
# Given the option string `a b:^`, -abX → -a -b X
|
||||
|
||||
# We need to peek at the next option
|
||||
__getopts_increase_index
|
||||
|
||||
# Check if next argument exists.
|
||||
if set -q argv[$__getopts_index]
|
||||
# Sanitize the option-argument.
|
||||
set -l value (printf "%s" $argv[$__getopts_index])
|
||||
if [ -z "$value" ]
|
||||
# Print any non-empty list character.
|
||||
printf "\n"
|
||||
else
|
||||
printf $value
|
||||
end
|
||||
__getopts_increase_index
|
||||
return $__CONTINUE
|
||||
else
|
||||
__getopts_cleanup
|
||||
return $__OPTION_ARGUMENT_EXPECTED
|
||||
end
|
||||
|
||||
# Option was a flag that takes no arguments.
|
||||
case \*
|
||||
__getopts_increase_index
|
||||
return $__CONTINUE
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# No match found. Print unknown option to stdout first, and
|
||||
# if strict mode is enabled, abort, else continue.
|
||||
printf $option
|
||||
__getopts_increase_index
|
||||
|
||||
# If the first character of the option string is a `:`, this
|
||||
# enables strict mode and any unknown options will cause the
|
||||
# process to return > 0.
|
||||
|
||||
if set -q __getopts_strict_mode
|
||||
__getopts_cleanup
|
||||
return $__UNKNOWN_OPTION_FOUND
|
||||
else
|
||||
return $__CONTINUE
|
||||
end
|
||||
|
||||
# Looks like we run out of options. Print operands return.
|
||||
case \*
|
||||
if [ $__getopts_index -gt 1 ]
|
||||
|
||||
# Sans the current index, get rid of everything up to here.
|
||||
set -e argv[1..(math $__getopts_index-1)]
|
||||
end
|
||||
printf "%s\n" $argv
|
||||
|
||||
__getopts_cleanup
|
||||
return $__END_OF_OPTIONS
|
||||
end
|
||||
else
|
||||
# End of arguments, cleanup and exit.
|
||||
__getopts_cleanup
|
||||
return $__END_OF_OPTIONS
|
||||
end
|
||||
end
|
|
@ -1,150 +0,0 @@
|
|||
import plugins/fish-spec
|
||||
import plugins/getopts
|
||||
|
||||
function describe_getotps -d "fish getopts"
|
||||
function __getopts
|
||||
set -l options $argv[1]
|
||||
set -e argv[1]
|
||||
while set option (getopts $options $argv)
|
||||
if [ (count $option) -gt 1 ] # w/ argument
|
||||
set result "$result$option[1]($option[2])"
|
||||
else
|
||||
set result "$result$option"
|
||||
end
|
||||
end
|
||||
printf "$result$option"
|
||||
end
|
||||
|
||||
function it_returns_1_if_empty
|
||||
getopts
|
||||
expect $status --to-equal 1
|
||||
end
|
||||
|
||||
function it_handles_a_single_short_option
|
||||
expect (__getopts "a" -a) --to-equal a
|
||||
end
|
||||
|
||||
function it_handles_a_single_long_option
|
||||
expect (__getopts "aa" --aa) --to-equal aa
|
||||
end
|
||||
|
||||
function it_handles_short_options
|
||||
set -l options "a b c x y z"
|
||||
set -l expected abcxyz
|
||||
expect (__getopts $options -abc -xyz) --to-equal $expected
|
||||
and expect (__getopts $options -a -b -c -x -y -z) --to-equal $expected
|
||||
end
|
||||
|
||||
function it_handles_long_options
|
||||
expect (__getopts "x-rays ye zombie" --ye --zombie --x-rays) \
|
||||
--to-equal yezombiex-rays
|
||||
end
|
||||
|
||||
function it_handles_long_options_only
|
||||
expect (__getopts "all blink crunch" --all --blink --crunch) \
|
||||
--to-equal allblinkcrunch
|
||||
end
|
||||
|
||||
function it_handles_all_options
|
||||
expect (__getopts "g:get p:put u:update d:delete t:post" -tud --put --get) \
|
||||
--to-equal tudpg
|
||||
end
|
||||
|
||||
function it_handles_operands
|
||||
expect (__getopts "" 1 2 3 4 5) --to-equal "1 2 3 4 5"
|
||||
end
|
||||
|
||||
function it_handles_options_and_operands
|
||||
expect (__getopts "g:get p:put u:update d:delete t:post" \
|
||||
-ud --put --get --post url1 url2 user:password) \
|
||||
--to-equal "udpgturl1 url2 user:password"
|
||||
end
|
||||
|
||||
function it_handles_end_of_args_separator
|
||||
expect (__getopts "a b c d" -abcd -- -x -y -z) --to-equal "abcd-x -y -z"
|
||||
end
|
||||
|
||||
function it_detects_end_of_args
|
||||
expect (__getopts "a b c" -abc 1 2 3 -x) --to-equal "abc1 2 3 -x"
|
||||
end
|
||||
|
||||
function it_returns_unknown_option_error_on_strict_mode
|
||||
while set option (getopts ":a b c d e f" -abcXdef 1 2 3)
|
||||
set result "$result$option"
|
||||
end
|
||||
|
||||
expect $status --to-equal 3
|
||||
end
|
||||
|
||||
function it_handles_valid_options_while_on_strict_mode
|
||||
while set option (getopts ":a b c d e f" -fed -cba 1 2 3)
|
||||
set result "$result$option"
|
||||
end
|
||||
|
||||
expect "$result" --to-equal fedcba
|
||||
and expect "$option" --to-equal "1 2 3"
|
||||
end
|
||||
|
||||
function it_returns_argument_missing_error_if_argument_is_missing
|
||||
while set option (getopts "x y z:" -xy -z)
|
||||
end
|
||||
|
||||
expect $status --to-equal 2
|
||||
end
|
||||
|
||||
function it_handles_options_normally_until_an_error_is_found
|
||||
while set option (getopts ":a b c d e f" -abcXdef 1 2 3)
|
||||
set result "$result$option"
|
||||
end
|
||||
|
||||
expect "$result" --to-equal abc
|
||||
expect "$option" --to-equal X
|
||||
end
|
||||
|
||||
function it_handles_short_options_separated_by_blanks
|
||||
expect (__getopts "a: b: c:" -a '1st arg' -b '2nd arg' -c '3rd arg') \
|
||||
--to-equal "a(1st arg)b(2nd arg)c(3rd arg)"
|
||||
end
|
||||
|
||||
function it_handles_a_short_option_w_required_argument_without_space_separation
|
||||
expect (__getopts "a: b:" -adarwin -blinux) --to-equal "a(darwin)b(linux)"
|
||||
end
|
||||
|
||||
function it_handles_a_short_option_w_optional_argument_with_space_separation
|
||||
expect (__getopts "a: b:^" -a darwin -b linux) --to-equal "a(darwin)b()linux"
|
||||
end
|
||||
|
||||
function it_handles_options_w_argument
|
||||
set -l url "http://github.com"
|
||||
set -l expected "pg($url)"
|
||||
set -l options "g:get: p:put"
|
||||
expect (__getopts $options -pg$url) --to-equal $expected
|
||||
and expect (__getopts $options -p --get $url) --to-equal $expected
|
||||
end
|
||||
|
||||
function it_handles_options_w_optional_argument
|
||||
set -l url "http://github.com"
|
||||
set -l expected "pg($url)"
|
||||
set -l options "g:get:^ p:put"
|
||||
expect (__getopts $options -pg$url) --to-equal $expected
|
||||
and expect (__getopts $options -p --get=$url) --to-equal $expected
|
||||
and expect (__getopts $options -pg) --to-equal "pg()"
|
||||
end
|
||||
|
||||
function it_handles_a_contrived_example
|
||||
set -l options "A b c: x y z: long long-req: long-opt:^"
|
||||
set -l args -xyz777 -Abc100 --long --long-req 32 --long-opt=!!! D O N E
|
||||
expect (__getopts $options $args) --to-equal \
|
||||
"xyz(777)Abc(100)longlong-req(32)long-opt(!!!)D O N E"
|
||||
end
|
||||
|
||||
function it_handles_multiline_option_strings
|
||||
set -l multiline_options "a:aaa
|
||||
b:bbb
|
||||
c:ccc
|
||||
d:ddd"
|
||||
expect (__getopts $multiline_options -dcbabcd) --to-equal "dcbabcd"
|
||||
end
|
||||
end
|
||||
|
||||
spec.run $argv
|
|
@ -1,23 +0,0 @@
|
|||
gitignore (gi) plugin
|
||||
=====================
|
||||
|
||||
This plugin provides a simple command line interface to gitignore.io - a
|
||||
website that generates .gitignore files based on your project requirements.
|
||||
|
||||
## Completions
|
||||
|
||||
The first step is to download the latest language list from gitignore.io so
|
||||
that the fish completions can be updated. Run `gi update-completions` to
|
||||
download the completions, they will be stored in
|
||||
`~/.config/fish/completions/gi.fish`
|
||||
|
||||
You should repeat this occasionally to keep up to date.
|
||||
|
||||
## Usage
|
||||
|
||||
Type `gi` followed by TAB to view the list of languages available. To generate
|
||||
a .gitignore file, specify the list of languages you are interested in and pipe
|
||||
the output into the destination file. Example for a go-lang project:
|
||||
|
||||
gi go tags vagrant > .gitignore
|
||||
git add .gitignore
|
|
@ -1,21 +0,0 @@
|
|||
function _update_gi_completions -d "Update completions for gitignore.io"
|
||||
set compl_dir ~/.config/fish/completions
|
||||
set compl_file "$compl_dir/gi.fish"
|
||||
|
||||
# Download list of ignore types
|
||||
set -l gi_list (gi list | tr ',' ' ')
|
||||
if test -z $gi_list
|
||||
echo "No result returned from gitignore.io" >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
# Backup existing completions
|
||||
if test -e $compl_file
|
||||
mv -f $compl_file {$compl_file}.bak
|
||||
else if not test -d $compl_dir
|
||||
mkdir -p $compl_dir
|
||||
end
|
||||
|
||||
# Output new completions
|
||||
echo complete -c gi -a \"update-completions $gi_list\" >$compl_file
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
function gi -d "gitignore.io cli for fish"
|
||||
if test $argv[1] = 'update-completions'
|
||||
_update_gi_completions
|
||||
return $status
|
||||
end
|
||||
|
||||
set -l params (echo $argv|tr ' ' ',')
|
||||
curl -s https://www.gitignore.io/api/$params
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
# git-flow
|
||||
|
||||
Completion support for git-flow.Fork from [bobthecow/git-flow-completion](https://github.com/bobthecow/git-flow-completion/blob/master/git.fish)
|
||||
|
||||
The contained completion routines provide support for completing:
|
||||
|
||||
- git-flow init and version
|
||||
|
||||
- feature, hotfix and release branches
|
||||
|
||||
- remote feature, hotfix and release branch names
|
||||
|
||||
# The Fine Print
|
||||
|
||||
Copyright (c) 2011 [Justin Hileman](http://justinhileman.com)
|
||||
|
||||
Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
|
||||
|
|
@ -1,185 +0,0 @@
|
|||
#!fish
|
||||
#
|
||||
# git-flow-completion
|
||||
# ===================
|
||||
#
|
||||
# Fish completion support for [git-flow](http://github.com/nvie/gitflow)
|
||||
#
|
||||
# The contained completion routines provide support for completing:
|
||||
#
|
||||
# * git-flow init and version
|
||||
# * feature, hotfix and release branches
|
||||
# * remote feature, hotfix and release branch names
|
||||
#
|
||||
#
|
||||
#
|
||||
# The Fine Print
|
||||
# --------------
|
||||
#
|
||||
# Copyright (c) 2012 [Justin Hileman](http://justinhileman.com)
|
||||
#
|
||||
# Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
|
||||
|
||||
|
||||
for prefix in /usr /usr/local
|
||||
if test -f $prefix/share/fish/completions/git.fish
|
||||
. $prefix/share/fish/completions/git.fish
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not functions -q __fish_git_branches
|
||||
echo \nError: git completion not found >&2
|
||||
exit
|
||||
end
|
||||
|
||||
## Support functions
|
||||
|
||||
function __fish_git_flow_using_command
|
||||
set cmd (commandline -opc)
|
||||
set subcommands 'flow' $argv
|
||||
if [ (count $cmd) = (math (count $subcommands) + 1) ]
|
||||
for i in (seq (count $subcommands))
|
||||
if not test $subcommands[$i] = $cmd[(math $i + 1)]
|
||||
return 1
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
function __fish_git_flow_prefix
|
||||
git config "gitflow.prefix.$argv[1]" 2> /dev/null; or echo "$argv[1]/"
|
||||
end
|
||||
|
||||
function __fish_git_flow_branches
|
||||
set prefix (__fish_git_flow_prefix $argv[1])
|
||||
__fish_git_branches | grep "^$prefix" | sed "s,^$prefix,," | sort
|
||||
end
|
||||
|
||||
function __fish_git_flow_remote_branches
|
||||
set prefix (__fish_git_flow_prefix $argv[1])
|
||||
set origin (git config gitflow.origin 2> /dev/null; or echo "origin")
|
||||
git branch -r 2> /dev/null | sed "s/^ *//g" | grep "^$origin/$prefix" | sed "s,^$origin/$prefix,," | sort
|
||||
end
|
||||
|
||||
function __fish_git_flow_untracked_branches
|
||||
set branches (__fish_git_flow_branches $argv[1])
|
||||
for branch in (__fish_git_flow_remote_branches $argv[1])
|
||||
if not contains $branch $branches
|
||||
echo $branch
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function __fish_git_flow_unpublished_branches
|
||||
set branches (__fish_git_flow_remote_branches $argv[1])
|
||||
for branch in (__fish_git_flow_branches $argv[1])
|
||||
if not contains $branch $branches
|
||||
echo $branch
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
## git-flow
|
||||
|
||||
complete -f -c git -n '__fish_git_needs_command' -a flow -d 'Manage a git-flow enabled repository'
|
||||
complete -f -c git -n '__fish_git_flow_using_command' -a version -d 'Show version information'
|
||||
|
||||
|
||||
|
||||
## git-flow init
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command' -a init -d 'Initialize a new git repo with support for the branching model'
|
||||
complete -f -c git -n '__fish_git_flow_using_command init' -s f -d 'Force reinitialization'
|
||||
complete -f -c git -n '__fish_git_flow_using_command init' -s d -d 'Use default branch names'
|
||||
|
||||
|
||||
|
||||
## git-flow feature
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command' -a feature -d 'Manage feature branches'
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature' -a list -d 'List feature branches'
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature' -s v -d 'Verbose output'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature' -a start -d 'Start a new feature branch'
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature start' -s F -d 'Fetch from origin first'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature' -a finish -d 'Finish a feature branch'
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature finish' -s F -d 'Fetch from origin first'
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature finish' -s r -d 'Rebase instead of merging'
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature finish' -a '(__fish_git_flow_branches feature)' -d 'Feature branch'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature' -a publish -d 'Publish a feature branch to remote'
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature publish' -a '(__fish_git_flow_unpublished_branches feature)' -d 'Feature branch'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature' -a track -d 'Checkout remote feature branch'
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature track' -a '(__fish_git_flow_untracked_branches feature)' -d 'Feature branch'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature' -a diff -d 'Show all changes'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature' -a rebase -d 'Rebase against integration branch'
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature rebase' -s i -d 'Do an interactive rebase'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature' -a checkout -d 'Checkout local feature branch'
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature checkout' -a '(__fish_git_flow_branches feature)' -d 'Feature branch'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature' -a pull -d 'Pull changes from remote'
|
||||
complete -f -c git -n '__fish_git_flow_using_command feature pull' -a '(__fish_git_remotes)' -d 'Remote'
|
||||
|
||||
|
||||
|
||||
## git-flow release
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command' -a release -d 'Manage release branches'
|
||||
complete -f -c git -n '__fish_git_flow_using_command release' -a list -d 'List release branches'
|
||||
complete -f -c git -n '__fish_git_flow_using_command release' -s v -d 'Verbose output'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command release' -a start -d 'Start a new release branch'
|
||||
complete -f -c git -n '__fish_git_flow_using_command release start' -s F -d 'Fetch from origin first'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command release' -a finish -d 'Finish a release branch'
|
||||
complete -f -c git -n '__fish_git_flow_using_command release finish' -s F -d 'Fetch from origin first'
|
||||
complete -f -c git -n '__fish_git_flow_using_command release finish' -s s -d 'Sign the release tag cryptographically'
|
||||
complete -f -c git -n '__fish_git_flow_using_command release finish' -s u -d 'Use the given GPG-key for the digital signature (implies -s)'
|
||||
complete -f -c git -n '__fish_git_flow_using_command release finish' -s m -d 'Use the given tag message'
|
||||
complete -f -c git -n '__fish_git_flow_using_command release finish' -s p -d 'Push to $ORIGIN after performing finish'
|
||||
complete -f -c git -n '__fish_git_flow_using_command release finish' -a '(__fish_git_flow_branches release)' -d 'Release branch'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command release' -a publish -d 'Publish a release branch to remote'
|
||||
complete -f -c git -n '__fish_git_flow_using_command release publish' -a '(__fish_git_flow_unpublished_branches release)' -d 'Release branch'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command release' -a track -d 'Checkout remote release branch'
|
||||
complete -f -c git -n '__fish_git_flow_using_command release track' -a '(__fish_git_flow_untracked_branches release)' -d 'Release branch'
|
||||
|
||||
|
||||
|
||||
## git-flow hotfix
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command' -a hotfix -d 'Manage hotfix branches'
|
||||
complete -f -c git -n '__fish_git_flow_using_command hotfix' -a list -d 'List hotfix branches'
|
||||
complete -f -c git -n '__fish_git_flow_using_command hotfix' -s v -d 'Verbose output'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command hotfix' -a start -d 'Start a new hotfix branch'
|
||||
complete -f -c git -n '__fish_git_flow_using_command hotfix start' -s F -d 'Fetch from origin first'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command hotfix' -a finish -d 'Finish a hotfix branch'
|
||||
complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s F -d 'Fetch from origin first'
|
||||
complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s s -d 'Sign the hotfix tag cryptographically'
|
||||
complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s u -d 'Use the given GPG-key for the digital signature (implies -s)'
|
||||
complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s m -d 'Use the given tag message'
|
||||
complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s p -d 'Push to $ORIGIN after performing finish'
|
||||
complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -a '(__fish_git_flow_branches hotfix)' -d 'Hotfix branch'
|
||||
|
||||
|
||||
|
||||
## git-flow support
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command' -a support -d 'Manage support branches'
|
||||
complete -f -c git -n '__fish_git_flow_using_command support' -a list -d 'List support branches'
|
||||
complete -f -c git -n '__fish_git_flow_using_command support' -s v -d 'Verbose output'
|
||||
|
||||
complete -f -c git -n '__fish_git_flow_using_command support' -a start -d 'Start a new support branch'
|
||||
complete -f -c git -n '__fish_git_flow_using_command support start' -s F -d 'Fetch from origin first'
|
|
@ -1,3 +0,0 @@
|
|||
function gvm
|
||||
bash -c '. ~/.gvm/bin/gvm-init.sh; gvm "$@"' gvm $argv
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
for gvm_path in (find $HOME/.gvm/*/current/bin -maxdepth 0)
|
||||
_prepend_path $gvm_path
|
||||
set -l module_info (echo $gvm_path | perl -ne 'm|(.*/.gvm/(\w+)/current)/bin| && print "$1 $2"')
|
||||
set -l module_dir (echo $module_info | awk -F' ' '{print $1}')
|
||||
set -l module_name (echo $module_info | awk -F' ' '{print $2}')
|
||||
set -l module_home (echo $module_name | tr '[:lower:]' '[:upper:]')_HOME
|
||||
set -gx "$module_home" $module_dir
|
||||
end
|
||||
|
||||
# ONLY checked on OSX! Please add for other OS's...
|
||||
if test -z $JAVA_HOME
|
||||
if test -f "/usr/libexec/java_home"
|
||||
set -gx JAVA_HOME (/usr/libexec/java_home)
|
||||
end
|
||||
|
||||
if test -z $JAVA_HOME
|
||||
set -l java_homes "/Library/Java/Home" "/System/Library/Frameworks/JavaVM.framework/Home"
|
||||
for file in $java_homes
|
||||
if test -d $file
|
||||
set -gx JAVA_HOME $file
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if test -z $JAVA_HOME
|
||||
echo "GVM: JAVA_HOME not set please set JAVA_HOME."
|
||||
end
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
jump
|
||||
====
|
||||
|
||||
A port of [Jeroen Janssens' "jump" utility] [1] to the fish shell (and [Oh My Fish!] [2]).
|
||||
|
||||
[1]: http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
|
||||
[2]: https://github.com/bpinto/oh-my-fish
|
|
@ -1,11 +0,0 @@
|
|||
function jump
|
||||
if test (count $argv) -ne 1
|
||||
echo "Usage: jump <MARK_NAME>"
|
||||
else
|
||||
if test -d $MARKPATH/$argv[1] -a -L $MARKPATH/$argv[1]
|
||||
cd $MARKPATH/$argv[1]
|
||||
else
|
||||
echo "No such mark: $argv[1]"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
set -gx MARKPATH $HOME/.marks
|
||||
command mkdir -p $MARKPATH
|
||||
|
||||
complete -c jump -f -a '(ls ~/.marks)'
|
||||
complete -c unmark -f -a '(ls ~/.marks)'
|
|
@ -1,22 +0,0 @@
|
|||
function mark
|
||||
if test (count $argv) -eq 0 -o (count $argv) -gt 2
|
||||
echo "Usage: mark <MARK_NAME> [DIRECTORY]"
|
||||
else if test -e $MARKPATH/$argv[1]
|
||||
if test -d $MARKPATH/$argv[1] -a -L $MARKPATH/$argv[1]
|
||||
echo "A mark named $argv[1] already exists."
|
||||
else
|
||||
echo "$MARKPATH/$argv[1] already exists."
|
||||
end
|
||||
else if test (count $argv) -eq 1
|
||||
command ln -s (pwd) $MARKPATH/$argv[1]
|
||||
else if test (count $argv) -eq 2
|
||||
if test -d $argv[2]
|
||||
set -l current_dir (pwd)
|
||||
cd $argv[2]
|
||||
command ln -s (pwd) $MARKPATH/$argv[1]
|
||||
cd $current_dir
|
||||
else
|
||||
echo "$argv[2] is not a valid directory."
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
function marks
|
||||
if test (count $argv) -gt 0
|
||||
echo "Usage: marks"
|
||||
else
|
||||
set -l file_list (command ls $MARKPATH)
|
||||
if test (count $file_list) -eq 0
|
||||
echo "No marks currently defined."
|
||||
else
|
||||
set -l mark_list
|
||||
for file in $file_list
|
||||
if test -d $MARKPATH/$file -a -L $MARKPATH/$file
|
||||
set mark_list $mark_list $file
|
||||
end
|
||||
end
|
||||
if test (count $mark_list) -eq 0
|
||||
echo "No marks currently defined."
|
||||
else
|
||||
set -l current_dir (pwd)
|
||||
set -l output ""
|
||||
for mark_name in $mark_list
|
||||
cd $MARKPATH/$mark_name
|
||||
set -l real_path (pwd)
|
||||
set output "$output$mark_name -> $real_path"\n
|
||||
end
|
||||
echo $output | column -t
|
||||
cd $current_dir
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
function unmark
|
||||
if test (count $argv) -eq 0
|
||||
echo "Usage: unmark <MARK_NAME>..."
|
||||
else
|
||||
for mark_name in $argv
|
||||
if test -d $MARKPATH/$mark_name -a -L $MARKPATH/$mark_name
|
||||
command rm -i $MARKPATH/$mark_name
|
||||
else
|
||||
echo "No such mark: $mark_name"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
# Load custom settings for current hostname
|
||||
set -l HOST (hostname | sed -E 's/(-[0-9]+)?(\.(local|home))?$//')
|
||||
set -l HOST_SPECIFIC_FILE $fish_custom/hosts/$HOST.fish
|
||||
if test -f $HOST_SPECIFIC_FILE
|
||||
. $HOST_SPECIFIC_FILE
|
||||
else
|
||||
echo Creating host specific file: $HOST_SPECIFIC_FILE
|
||||
mkdir -p (dirname $HOST_SPECIFIC_FILE)
|
||||
touch $HOST_SPECIFIC_FILE
|
||||
end
|
||||
|
||||
# Load custom settings for current user
|
||||
set -l USER_SPECIFIC_FILE $fish_custom/users/(whoami).fish
|
||||
if test -f $USER_SPECIFIC_FILE
|
||||
. $USER_SPECIFIC_FILE
|
||||
else
|
||||
echo Creating user specific file: $USER_SPECIFIC_FILE
|
||||
mkdir -p (dirname $USER_SPECIFIC_FILE)
|
||||
touch $USER_SPECIFIC_FILE
|
||||
end
|
||||
|
||||
# Load custom settings for current OS
|
||||
set -l PLATFORM_SPECIFIC_FILE $fish_custom/platforms/(uname -s).fish
|
||||
if test -f $PLATFORM_SPECIFIC_FILE
|
||||
. $PLATFORM_SPECIFIC_FILE
|
||||
else
|
||||
echo Creating platform specific file: $PLATFORM_SPECIFIC_FILE
|
||||
mkdir -p (dirname $PLATFORM_SPECIFIC_FILE)
|
||||
touch $PLATFORM_SPECIFIC_FILE
|
||||
end
|
|
@ -1,33 +0,0 @@
|
|||
# Opens http://localhost:3000 (and other ports) in the default browser
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# open a commonly used port with just the port number
|
||||
# $ 3000
|
||||
#
|
||||
# open an arbitrary port using the `lh` command
|
||||
# $ lh 3001
|
||||
|
||||
## Functions
|
||||
function _open-installed
|
||||
which open >/dev/null ^&1
|
||||
end
|
||||
|
||||
## Main program
|
||||
function lh
|
||||
if _open-installed
|
||||
if [ (count $argv) -lt 1 ]
|
||||
echo "You need to specify a port to open"
|
||||
return 1
|
||||
end
|
||||
command open http://localhost:$argv
|
||||
else
|
||||
echo 'Requires open (MacOS only) to be installed'
|
||||
end
|
||||
end
|
||||
|
||||
set -l common_localhost_ports 3000 4000 5000 6000 7000 8000 8001 9000 8080
|
||||
|
||||
for port in $common_localhost_ports
|
||||
eval "function $port; lh $port; end"
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
function mc --description "Visual shell for Unix-like systems."
|
||||
set -lx SHELL sh
|
||||
if which bash > /dev/null
|
||||
set SHELL (which bash)
|
||||
end
|
||||
command mc $argv
|
||||
end
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# Print a message with msg and wait for y/n input. Return true on y\*.
|
||||
# @params → msg.fish
|
||||
function msg.ask
|
||||
msg $argv
|
||||
head -n 1 | read answer
|
||||
switch $answer
|
||||
case y\* Y\*
|
||||
return 0
|
||||
case \*
|
||||
return 1
|
||||
end
|
||||
end
|
|
@ -1,164 +0,0 @@
|
|||
# __ _ ___ ___ _
|
||||
# / ' \(_-</ _ `/
|
||||
# /_/_/_/___/\_, /
|
||||
# /___/ v0.1.0
|
||||
# NAME
|
||||
# msg - technicolor message printer
|
||||
#
|
||||
# SYNOPSIS
|
||||
# msg [-sn] [@<fg:bg> | style]<text>[style]
|
||||
#
|
||||
# OPTIONS
|
||||
# -s
|
||||
# Do not separate arguments with spaces.
|
||||
# -n
|
||||
# Do not output a newline at the end of the message.
|
||||
#
|
||||
# STYLES
|
||||
# _text_ Bold
|
||||
# __text__ Underline
|
||||
# ___text___ Bold and Underline
|
||||
# `$variable` Apply @<styles> to $variables
|
||||
# /directory/ Directories
|
||||
# [url] Links
|
||||
# \n Line Break
|
||||
# \t Tab Space
|
||||
#
|
||||
# @<fg:bg> fg=bg=RGB|RRGGBB|name|random
|
||||
# RGB value can be any three to six hex digit or color name.
|
||||
# e.g, @0fb, @tomato, @random, @error, @ok.
|
||||
#
|
||||
# NOTES
|
||||
# Escape style separators or options prepending a \ to the
|
||||
# string if inside quotes `msg "\-s"` or a \\ backslash in
|
||||
# order to escape the backslash itself when outside quotes.
|
||||
#
|
||||
# AUTHORS
|
||||
# Jorge Bucaran <jbucaran@me.com>
|
||||
#
|
||||
# v. 0.1.0
|
||||
#/
|
||||
|
||||
# Global `msg` default color and styles.
|
||||
set --global msg_color_fg FFFFFF
|
||||
set --global msg_color_bg normal
|
||||
set --global msg_style_url 00FF00 $msg_color_bg -u
|
||||
set --global msg_style_dir FFA500 $msg_color_bg -u
|
||||
set --global msg_color_err FF0000
|
||||
set --global msg_color_ok 00FA9A
|
||||
|
||||
function msg -d "Technicolor printer."
|
||||
# Default " " whitespace between strings, skip with -s.
|
||||
set -l ws " "
|
||||
# Default \n newline after message, skip with -n.
|
||||
set -l ln \n
|
||||
|
||||
switch (count $argv)
|
||||
case 0
|
||||
# Nothing to print here.
|
||||
return 0
|
||||
case \*
|
||||
switch $argv[1]
|
||||
# Options must appear joined and without spaces: -sn or -ns
|
||||
case -s\* -n\*
|
||||
# To use options at least a second parameter will be required.
|
||||
if [ (count $argv) -gt 1 ]
|
||||
# Use -s to not add spaces between words.
|
||||
if msg.util.str.has "s" $argv[1]
|
||||
set ws ""
|
||||
end
|
||||
# Use -n to not add a newline at the end of the message.
|
||||
if msg.util.str.has "n" $argv[1]
|
||||
set ln ""
|
||||
end
|
||||
# We are done with options, get rid of first item.
|
||||
set argv $argv[2..-1]
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Print flow is get next style token, set style, get anything else, print
|
||||
# and use the reset. set_color normal makes sure to reset both colors and
|
||||
# bold / underline styles.
|
||||
set -l reset (set_color normal)(set_color $msg_color_fg)
|
||||
|
||||
# Foreground and background color carried from previous @style token.
|
||||
# These variables are set and reset via msg.util.set.color
|
||||
set -l fg $msg_color_fg
|
||||
set -l bg $msg_color_bg
|
||||
|
||||
for token in $argv
|
||||
switch $token
|
||||
# Parse style tokens:
|
||||
# _txt_, __txt__, ___txt___, @color `$var`, /dir/, [url]
|
||||
case ___\*___\* __\*__\* _\*_\* \[\*\]\* \/\*\/\* `\*`\*
|
||||
set -l left _ # Begin of style
|
||||
set -l right _ # End of style
|
||||
set -l color $fg $bg -o
|
||||
switch $token
|
||||
case ___\*___\* __\*__\* _\*_\*
|
||||
if msg.util.str.has __ $token
|
||||
set color[3] -u
|
||||
set left __
|
||||
if msg.util.str.has ___ $token
|
||||
set color[3] -uo
|
||||
set left ___
|
||||
end
|
||||
end
|
||||
case \[\*\]\*
|
||||
set color $msg_style_url
|
||||
set left [ ]
|
||||
set right ]
|
||||
case \/\*\/\*
|
||||
set color $msg_style_dir
|
||||
set left \/
|
||||
set right \/
|
||||
case `\*`\*
|
||||
set color $fg $bg
|
||||
set left `
|
||||
set right `
|
||||
end
|
||||
|
||||
# Extract text between left and right separators.
|
||||
echo -n (msg.util.set.color $color)(msg.util.str.get $left $token)$reset
|
||||
|
||||
# Extract string after separator from the right.
|
||||
echo -n (printf $token | sed "s/^.*\\$right\(.*\)/\1/")$ws
|
||||
|
||||
# Parse @fg:bg style tokens.
|
||||
case @\*
|
||||
set fg (printf $token | cut -c 2-) # @fg[:bg] → fg[:bg]
|
||||
set bg (printf $fg | cut -d: -f 2) # fg:bg → fg|bg
|
||||
set fg (printf $fg | cut -d: -f 1) # fg:bg → fg
|
||||
|
||||
# Do not let bg=fg have the same color unless the user wants to.
|
||||
if [ $bg = $fg ]
|
||||
if not msg.util.str.has : $token
|
||||
set bg $msg_color_bg
|
||||
end
|
||||
end
|
||||
|
||||
# Make color string into valid RRGGBB hex format code.
|
||||
set fg (msg.util.get.color $fg)
|
||||
set bg (msg.util.get.color $bg)
|
||||
|
||||
# Everything else, print tokens, whitespace, etc.
|
||||
case \*
|
||||
set -l blank $ws
|
||||
switch $token
|
||||
# Do not print whitespace after the following characters.
|
||||
case $argv[-1] \n\* \t\* \r
|
||||
set blank ""
|
||||
end
|
||||
switch $token
|
||||
# Escape -s -n options and style separators \\[text] \\/text/
|
||||
case \\\[\* \\\/\* \\\_\* \\\-s \\\-n
|
||||
set token (printf $token | sed "s/^\\\//")
|
||||
end
|
||||
echo -en (msg.util.set.color)$token$reset$blank
|
||||
end
|
||||
end
|
||||
echo -en $ln
|
||||
end
|
|
@ -1,300 +0,0 @@
|
|||
# Translate color names to valid RRGGBB hexadecimal value.
|
||||
# @params <color|random>
|
||||
function msg.util.get.color
|
||||
[ (count $argv) -lt 1 ]
|
||||
and printf $msg_color_fg
|
||||
switch $argv[1]
|
||||
case success ok
|
||||
printf "%s\n" $msg_color_ok
|
||||
case error
|
||||
printf "%s\n" $msg_color_err
|
||||
case random
|
||||
msg.util.random.color
|
||||
case light
|
||||
# Higher values produce lighter colors.
|
||||
msg.util.random.color 100
|
||||
case dark
|
||||
# Lower values produce darker colors.
|
||||
msg.util.random.color 0 75
|
||||
case maroon
|
||||
printf 800000
|
||||
case d\*red
|
||||
printf 8B0000
|
||||
case brown
|
||||
printf A52A2A
|
||||
case firebrick
|
||||
printf B22222
|
||||
case crimson
|
||||
printf DC143C
|
||||
case red
|
||||
printf FF0000
|
||||
case tomato
|
||||
printf FF6347
|
||||
case coral
|
||||
printf FF7F50
|
||||
case indianred
|
||||
printf CD5C5C
|
||||
case l\*coral
|
||||
printf F08080
|
||||
case d\*salmon
|
||||
printf E9967A
|
||||
case salmon
|
||||
printf FA8072
|
||||
case l\*salmon
|
||||
printf FFA07A
|
||||
case orangered
|
||||
printf FF4500
|
||||
case d\*orange
|
||||
printf FF8C00
|
||||
case orange
|
||||
printf FFA500
|
||||
case gold
|
||||
printf FFD700
|
||||
case d\*goldenrod
|
||||
printf B8860B
|
||||
case goldenrod
|
||||
printf DAA520
|
||||
case palegoldenrod
|
||||
printf EEE8AA
|
||||
case d\*khaki
|
||||
printf BDB76B
|
||||
case khaki
|
||||
printf F0E68C
|
||||
case olive
|
||||
printf 808000
|
||||
case yellow
|
||||
printf FFFF00
|
||||
case yellowgreen
|
||||
printf 9ACD32
|
||||
case d\*olivegreen
|
||||
printf 556B2F
|
||||
case olivedrab
|
||||
printf 6B8E23
|
||||
case lawngreen
|
||||
printf 7CFC00
|
||||
case chartreuse
|
||||
printf 7FFF00
|
||||
case greenyellow
|
||||
printf ADFF2F
|
||||
case d\*green
|
||||
printf 006400
|
||||
case green
|
||||
printf 008000
|
||||
case forestgreen
|
||||
printf 228B22
|
||||
case lime
|
||||
printf 00FF00
|
||||
case limegreen
|
||||
printf 32CD32
|
||||
case l\*green
|
||||
printf 90EE90
|
||||
case palegreen
|
||||
printf 98FB98
|
||||
case d\*seagreen
|
||||
printf 8FBC8F
|
||||
case mediumspringgreen
|
||||
printf 00FA9A
|
||||
case springgreen
|
||||
printf 00FF7F
|
||||
case sea green
|
||||
printf 2E8B57
|
||||
case mediumaquamarine
|
||||
printf 66CDAA
|
||||
case mediumseagreen
|
||||
printf 3CB371
|
||||
case l\*seagreen
|
||||
printf 20B2AA
|
||||
case d\*slategray
|
||||
printf 2F4F4F
|
||||
case teal
|
||||
printf 008080
|
||||
case d\*cyan
|
||||
printf 008B8B
|
||||
case aqua
|
||||
printf 00FFFF
|
||||
case cyan
|
||||
printf 00FFFF
|
||||
case l\*cyan
|
||||
printf E0FFFF
|
||||
case d\*turquoise
|
||||
printf 00CED1
|
||||
case turquoise
|
||||
printf 40E0D0
|
||||
case mediumturquoise
|
||||
printf 48D1CC
|
||||
case paleturquoise
|
||||
printf AFEEEE
|
||||
case aquamarine
|
||||
printf 7FFFD4
|
||||
case powderblue
|
||||
printf B0E0E6
|
||||
case cadetblue
|
||||
printf 5F9EA0
|
||||
case steelblue
|
||||
printf 4682B4
|
||||
case cornflowerblue
|
||||
printf 6495ED
|
||||
case deepskyblue
|
||||
printf 00BFFF
|
||||
case dodgerblue
|
||||
printf 1E90FF
|
||||
case l\*blue
|
||||
printf ADD8E6
|
||||
case skyblue
|
||||
printf 87CEEB
|
||||
case l\*skyblue
|
||||
printf 87CEFA
|
||||
case midnightblue
|
||||
printf 191970
|
||||
case navy
|
||||
printf 000080
|
||||
case d\*blue
|
||||
printf 00008B
|
||||
case mediumblue
|
||||
printf 0000CD
|
||||
case blue
|
||||
printf 0000FF
|
||||
case royalblue
|
||||
printf 4169E1
|
||||
case blueviolet
|
||||
printf 8A2BE2
|
||||
case indigo
|
||||
printf 4B0082
|
||||
case d\*slateblue
|
||||
printf 483D8B
|
||||
case slateblue
|
||||
printf 6A5ACD
|
||||
case mediumslateblue
|
||||
printf 7B68EE
|
||||
case mediumpurple
|
||||
printf 9370DB
|
||||
case d\*magenta
|
||||
printf 8B008B
|
||||
case d\*violet
|
||||
printf 9400D3
|
||||
case d\*orchid
|
||||
printf 9932CC
|
||||
case mediumorchid
|
||||
printf BA55D3
|
||||
case purple
|
||||
printf 800080
|
||||
case thistle
|
||||
printf D8BFD8
|
||||
case plum
|
||||
printf DDA0DD
|
||||
case violet
|
||||
printf EE82EE
|
||||
case magenta fuchsia
|
||||
printf FF00FF
|
||||
case orchid
|
||||
printf DA70D6
|
||||
case mediumvioletred
|
||||
printf C71585
|
||||
case palevioletred
|
||||
printf DB7093
|
||||
case deeppink
|
||||
printf FF1493
|
||||
case hotpink
|
||||
printf FF69B4
|
||||
case l\*pink
|
||||
printf FFB6C1
|
||||
case pink
|
||||
printf FFC0CB
|
||||
case antiquewhite
|
||||
printf FAEBD7
|
||||
case beige
|
||||
printf F5F5DC
|
||||
case bisque
|
||||
printf FFE4C4
|
||||
case blanchedalmond
|
||||
printf FFEBCD
|
||||
case wheat
|
||||
printf F5DEB3
|
||||
case cornsilk
|
||||
printf FFF8DC
|
||||
case lemonchiffon
|
||||
printf FFFACD
|
||||
case l\*goldenrodyellow
|
||||
printf FAFAD2
|
||||
case l\*yellow
|
||||
printf FFFFE0
|
||||
case saddlebrown
|
||||
printf 8B4513
|
||||
case sienna
|
||||
printf A0522D
|
||||
case choco chocolate
|
||||
printf D2691E
|
||||
case peru
|
||||
printf CD853F
|
||||
case sandybrown
|
||||
printf F4A460
|
||||
case burlywood
|
||||
printf DEB887
|
||||
case tan
|
||||
printf D2B48C
|
||||
case rosybrown
|
||||
printf BC8F8F
|
||||
case moccasin
|
||||
printf FFE4B5
|
||||
case navajowhite
|
||||
printf FFDEAD
|
||||
case peach peachpuff
|
||||
printf FFDAB9
|
||||
case rose mistyrose
|
||||
printf FFE4E1
|
||||
case lavenderblush
|
||||
printf FFF0F5
|
||||
case linen
|
||||
printf FAF0E6
|
||||
case oldlace
|
||||
printf FDF5E6
|
||||
case papaya papayawhip
|
||||
printf FFEFD5
|
||||
case seashell
|
||||
printf FFF5EE
|
||||
case mintcream
|
||||
printf F5FFFA
|
||||
case slategray
|
||||
printf 708090
|
||||
case l\*slategray
|
||||
printf 778899
|
||||
case l\*steelblue
|
||||
printf B0C4DE
|
||||
case lavender
|
||||
printf E6E6FA
|
||||
case floralwhite
|
||||
printf FFFAF0
|
||||
case aliceblue
|
||||
printf F0F8FF
|
||||
case ghostwhite
|
||||
printf F8F8FF
|
||||
case honeydew
|
||||
printf F0FFF0
|
||||
case ivory
|
||||
printf FFFFF0
|
||||
case azure
|
||||
printf F0FFFF
|
||||
case snow
|
||||
printf FFFAFA
|
||||
case black
|
||||
printf 000000
|
||||
case dimgray dimgrey
|
||||
printf 696969
|
||||
case gray grey
|
||||
printf 808080
|
||||
case d\*gray d\*grey
|
||||
printf A9A9A9
|
||||
case silver
|
||||
printf C0C0C0
|
||||
case l\*gray l\*grey
|
||||
printf D3D3D3
|
||||
case gainsboro
|
||||
printf DCDCDC
|
||||
case whitesmoke
|
||||
printf F5F5F5
|
||||
case white
|
||||
printf FFFFFF
|
||||
case "*"
|
||||
printf $argv[1]
|
||||
end
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
# Print a random RRGGBB hexadecimal color from three min~max random beams
|
||||
# where min = 0 and max = 255. Higher values produce lighter colors.
|
||||
# @params [<min>][<max>]
|
||||
function msg.util.random.color
|
||||
set -l min 0
|
||||
if [ (count $argv) -gt 0 ]
|
||||
set min $argv[1]
|
||||
end
|
||||
|
||||
set -l max 255
|
||||
if [ (count $argv) -gt 1 ]
|
||||
set max $argv[2]
|
||||
end
|
||||
|
||||
set beam "math (random)%\($max-$min+1\)+$min"
|
||||
printf "%02x%02x%02x" (eval $beam) (eval $beam) (eval $beam)
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
# Set style, fg/bg colors and reset. Modifies its parent scope of `msg`.
|
||||
# @params [<fg>] [<bg>] [<style>]
|
||||
function --no-scope-shadowing msg.util.set.color
|
||||
if [ (count $argv) -gt 0 ]
|
||||
set fg $argv[1]
|
||||
end
|
||||
|
||||
if [ (count $argv) -gt 1 ]
|
||||
set bg $argv[2]
|
||||
end
|
||||
|
||||
set_color -b $bg
|
||||
set_color $fg
|
||||
|
||||
if [ (count $argv) -gt 2 ]
|
||||
set_color $argv[3]
|
||||
end
|
||||
|
||||
set bg $msg_color_bg
|
||||
set fg $msg_color_fg
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
# Extract string between left and right separators of variable length.
|
||||
# @params <left-sep> [<right-sep>] <string>
|
||||
function msg.util.str.get
|
||||
set -l left $argv[1]
|
||||
set -l right $argv[1]
|
||||
set -l string $argv[2]
|
||||
|
||||
if [ (count $argv) -gt 2 ]
|
||||
set right $argv[2]
|
||||
set string $argv[3]
|
||||
end
|
||||
|
||||
set -l len (printf $left | awk '{print length}')
|
||||
# Match between outermost left / right separators.
|
||||
printf $string | sed "s/[^\\$left]*\(\\$left.*\\$right\)*/\1/g" | \
|
||||
sed "s/^.\{$len\}\(.*\).\{$len\}\$/\1/"
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
# True if substring exists in string.
|
||||
# @params <substring> <string>
|
||||
function msg.util.str.has
|
||||
printf $argv[2] | grep -q $argv[1]
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
if test -n "$NDENV_ROOT"
|
||||
_prepend_path $NDENV_ROOT/bin
|
||||
_prepend_path $NDENV_ROOT/shims
|
||||
else
|
||||
_prepend_path $HOME/.ndenv/bin
|
||||
_prepend_path $HOME/.ndenv/shims
|
||||
end
|
|
@ -1,4 +0,0 @@
|
|||
### Main program
|
||||
_prepend_path /usr/local/share/npm/bin
|
||||
|
||||
set PATH ./node_modules/.bin $PATH
|
|
@ -1,7 +0,0 @@
|
|||
if test -n "$NODENV_ROOT"
|
||||
_prepend_path $NODENV_ROOT/bin
|
||||
else
|
||||
_prepend_path $HOME/.nodenv/bin
|
||||
end
|
||||
|
||||
status --is-interactive; and source (nodenv init - | psub)
|
|
@ -1,17 +0,0 @@
|
|||
osx
|
||||
---
|
||||
|
||||
**Maintainer:** [cykeb](https://github.com/CYKEB)
|
||||
|
||||
Inspired by the oh-my-zsh plugin by [sorin-ionescu](https://github.com/sorin-ionescu)
|
||||
https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/osx/osx.plugin.zsh
|
||||
|
||||
- `tab` - Open the current directory in a new tab
|
||||
- `pfd` - Return the path of the frontmost Finder window
|
||||
- `pfs` - Return the current Finder selection
|
||||
- `cdf` - cd to the current Finder directory
|
||||
- `pushdf` - pushd to the current Finder directory
|
||||
- `ql` - Quick Look a specified file
|
||||
- `manp` - Open a specified man page in Preview
|
||||
- `trash` - Move a specified file to the Trash
|
||||
- `itunes` - Play, pause etc. iTunes
|
|
@ -1,5 +0,0 @@
|
|||
# cd to the current Finder directory
|
||||
|
||||
function cdf -d "cd to the current Finder directory"
|
||||
cd (pfd)
|
||||
end
|
|
@ -1,33 +0,0 @@
|
|||
# Play, pause etc. iTunes
|
||||
|
||||
function itunes -d "Play, pause etc. iTunes. Use -h or --help for a more detailed description."
|
||||
if [ (count $argv) -gt 0 ]
|
||||
set -l opt $argv[1]
|
||||
switch $opt
|
||||
case launch play pause stop rewind resume quit
|
||||
case mute
|
||||
set opt "set mute to true"
|
||||
case unmute
|
||||
set opt "set mute to false"
|
||||
case next previous
|
||||
set opt "$opt track"
|
||||
case vol volume
|
||||
set opt "set sound volume to $argv[2]"
|
||||
case "" -h --help
|
||||
echo "Usage: itunes <option>"
|
||||
echo "option:"
|
||||
echo \t"launch|play|pause|stop|rewind|resume|quit"
|
||||
echo \t"mute|unmute\tcontrol volume set"
|
||||
echo \t"next|previous\tplay next or previous track"
|
||||
echo \t"vol"\t"Set the volume, takes an argument from 0 to 100"
|
||||
echo \t"help"\t"show this message and exit"
|
||||
return 0
|
||||
case '*'
|
||||
echo "Unknown option $opt. Use -h or --help for a more detailed description."
|
||||
return 1
|
||||
end
|
||||
osascript -e "tell application \"iTunes\" to $opt"
|
||||
else
|
||||
echo "Arguments expected. Use -h or --help for a more detailed description."
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
# Open a specified man page in Preview
|
||||
|
||||
function manp -d "Open a specified man page in Preview"
|
||||
man -t $argv | open -f -a Preview
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
# Return the path of the frontmost Finder window
|
||||
|
||||
function pfd -d "Return the path of the frontmost Finder window"
|
||||
osascript 2>/dev/null -e '
|
||||
tell application "Finder"
|
||||
return POSIX path of (target of window 1 as alias)
|
||||
end tell'
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user