Skip to content

Commit

Permalink
Merge pull request #43 from terlar/feature/update-install-method
Browse files Browse the repository at this point in the history
Update Makefile and project structure
  • Loading branch information
terlar committed Apr 15, 2016
2 parents d63ed4c + c2fd02b commit 4c18d70
Show file tree
Hide file tree
Showing 23 changed files with 199 additions and 33 deletions.
65 changes: 49 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,94 @@ VERSION=0.1.5
AUTHOR=terlar
URL=https://github.com/$(AUTHOR)/$(NAME)

DIRS=etc lib bin sbin share
INSTALL_DIRS=`find $(DIRS) -type d 2>/dev/null`
INSTALL_FILES=`find $(DIRS) -type f 2>/dev/null`
DOC_FILES=*.md

# Packaging
PKG_DIR=pkg
PKG_NAME=$(NAME)-$(VERSION)
PKG=$(PKG_DIR)/$(PKG_NAME).tar.gz
SIG=$(PKG_DIR)/$(PKG_NAME).asc

PREFIX?=/usr/local
DOC_DIR=$(PREFIX)/share/doc/$(PKG_NAME)
# Installation directories
PREFIX ?= /usr
DESTDIR ?=
MANDIR ?= $(PREFIX)/share/man
FISHDIR ?= $(DESTDIR)$(PREFIX)/share/fish

COMPLETIONS_DIR_FILES := $(wildcard completions/*.fish)
FUNCTIONS_DIR_FILES := $(wildcard functions/*.fish)

pkg:
mkdir $(PKG_DIR)

download: pkg
wget -O $(PKG) $(URL)/archive/v$(VERSION).tar.gz
wget -O $(PKG) $(URL)/archive/$(VERSION).tar.gz

.PHONY: build
build: pkg
git archive --output=$(PKG) --prefix=$(PKG_NAME)/ HEAD

.PHONY: sign
sign: $(PKG)
gpg --sign --detach-sign --armor $(PKG)
git add $(PKG).asc
git commit $(PKG).asc -m "Added PGP signature for v$(VERSION)"
git push

.PHONY: verify
verify: $(PKG) $(SIG)
gpg --verify $(SIG) $(PKG)

.PHONY: clean
clean:
rm -f $(PKG) $(SIG)

.PHONY: all
all: $(PKG) $(SIG)

.PHONY: test
test:
fish test/runner.fish

.PHONY: tag
tag:
git push
git tag -s -m "Tagging $(VERSION)" v$(VERSION)
git push --tags

.PHONY: release
release: tag download sign

.PHONY: install
install:
for dir in $(INSTALL_DIRS); do mkdir -p $(PREFIX)/$$dir; done
for file in $(INSTALL_FILES); do cp $$file $(PREFIX)/$$file; done
mkdir -p $(DOC_DIR)
cp -r $(DOC_FILES) $(DOC_DIR)/

install -D -m644 man/man1/fry.1 "$(DESTDIR)$(MANDIR)/man1/fry.1"
install -D -m644 $(CURDIR)/conf.d/fry.fish $(FISHDIR)/vendor_conf.d/
for i in $(COMPLETIONS_DIR_FILES:%='%'); do \
install -D -m644 $$i $(FISHDIR)/vendor_completions.d/; \
true; \
done;
for i in $(FUNCTIONS_DIR_FILES:%='%'); do \
install -D -m644 $$i $(FISHDIR)/vendor_functions.d/; \
true; \
done;

.PHONY: uninstall
uninstall:
for file in $(INSTALL_FILES); do rm -f $(PREFIX)/$$file; done
rm -rf $(DOC_DIR)
-rm -f $(FISHDIR)/vendor_conf.d/fry.fish
-if test -d $(FISHDIR)/vendor_completions.d; then \
for i in $(COMPLETIONS_DIR_FILES); do \
basename=`basename $$i`; \
if test -f $(FISHDIR)/vendor_completions.d/$$basename; then \
rm $(FISHDIR)/vendor_completions.d/$$basename; \
fi; \
done; \
fi;
-if test -d $(FISHDIR)/vendor_functions.d; then \
for i in $(FUNCTIONS_DIR_FILES); do \
basename=`basename $$i`; \
if test -f $(FISHDIR)/vendor_functions.d/$$basename; then \
rm $(FISHDIR)/vendor_functions.d/$$basename; \
fi; \
done; \
fi;
rm -rf $(MANDIR)/man1/fry.1

.DEFAULT_GOAL:=build
.PHONY: build download sign verify clean test tag release install uninstall all
2 changes: 1 addition & 1 deletion share/fry/completions/fry.fish → completions/fry.fish
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function __fish_fry_using_command
end

function __fish_fry
fry help | grep ' ' | sed 's|^ *||;s|[<[].*[]>] ||' | unexpand -t2
fry help | string match ' *' | string replace -r '^\s+(\w+)\s([<\[].*[\]>]\s)*\s+(.*)' '$1\t$3'
end

complete -f -c fry -n '__fish_fry_needs_command' -a '(__fish_fry)'
Expand Down
11 changes: 0 additions & 11 deletions share/fry/fry.fish → conf.d/fry.fish
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ set -q fry_rubies ; or set -U fry_rubies $HOME/.rubies

test -d $fry_rubies; or mkdir -p $fry_rubies

# Path
set -l fry_path (dirname (status -f))

if not contains $fry_path/functions $fish_function_path
set fish_function_path $fry_path/functions $fish_function_path
end

if not contains $fry_path/completions $fish_complete_path
set fish_complete_path $fry_path/completions $fish_complete_path
end

# Installer
function __fry_installer_toggle --on-variable fry_installer
set -l installer fry-installer-$fry_installer
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
141 changes: 141 additions & 0 deletions man/man1/fry.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
.TH FRY 1 "2016-04-14" "0\&.1\&.5" "fish"
.SH NAME
fry \- a simple ruby version manager for fish
.SH SYNOPSIS
.B fry
.RI [\| ruby \|]
.\" Run a subcommand
.br
.B fry
.RI [\| command
.IR args \|]
.\" --help
.br
.B fry
.RB [\| \-h \||\| \-\-help \|]
.\" The subcommand find
.br
.B fry
.B find
.I search
.\" The subcommand current
.br
.B fry
.B current
.RB [\| \--path \|]
.RB [\| \-h \||\| \-\-help \|]
.\" The subcommand use
.br
.B fry
.B use
.I ruby
.\" The subcommand env
.br
.B fry
.B env
.RI [\| ruby \|]
.\" The subcommand install
.br
.B fry
.B install
.I ruby
.\" The subcommand config
.br
.B fry
.B config
.RI [\| name
.RI [\| value \|]\|]
.SH DESCRIPTION
.B fry
is a simple
.I ruby
switcher.
.SH EXAMPLES
.TP \w'fry\ 'u
.B fry ls
List available rubies.
This is a plain output that could be used for scripting.
.TP
.B fry rubies
List available rubies with the current one highlighted.
.TP
.BI fry\ find \ search
Fuzzy find available ruby based on the provided
.I search
string.
The result is using the latest version for an ambigous match.
If you want to find the latest jruby you can provide the
.I search
jruby.
If you are searching for MRI versions it is sufficient enough to just provide the version number.
Providing the
.I search
2.1 could result in ruby-2.1.5 if that is the highest version that was installed for the 2.1 branch.
.TP
.B fry current
Show the current ruby.
.TP
.B fry current --path
Show the path of the current ruby.
.TP
.BI fry\ use \ ruby
Use the provided
.IR ruby .
This will use the same logic as find to get the ruby version.
.TP
.B fry env
Output POSIX compatible environment.
This ouputs an export of the PATH variable including the prepended
.I ruby
path.
.TP
.BI fry\ env \ ruby
Output POSIX compatible environment for the provided
.IR ruby .
.TP
.BI fry\ install \ ruby
Install the provided
.IR ruby .
This requires that you have one of the available installers.
By default they are either
.I ruby-build
or
.IR ruby-install .
You can provide your own custom ruby installers by implementing a fish function named as
.I fry-installer-implementation
where
.I implementation
is the name of your implementation. This function in turn needs to define two functions inside. The function
.I __fry_install_ruby
which handles the installation and
.I __fry_install_rubies
which returns a list of available ruby versions.
This allows for the completion script and help to output which versions are available. For more information check the implementation of the
.I fry-installer-ruby-build
or
.I fry-installer-ruby-install
, this can be done by running
.IR functions fry-installer-ruby-build .
.TP
.B fry installers
List all available installers.
.TP
.B fry config
Display the available configuration and the current configuration.
.TP
.BI fry\ config \ name
Display the current configuration for the option provided by
.IR name .
.TP
.BI fry\ config \ name\ value
Set the configuration to
.I value
for the option provided by
.IR name .
.TP
.B fry version
Display the current version.
.TP
.B fry help
Display the help information.
.TP
2 changes: 1 addition & 1 deletion script/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ppa=ppa:fish-shell/${FISH_PPA:-nightly-master}
sudo add-apt-repository -y $ppa
sudo apt-get update
sudo apt-get -y install fish
sudo apt-get -y install fish realpath

curl -Lso fish-tank-master.tar.gz https://github.com/terlar/fish-tank/archive/master.tar.gz
tar -zxf fish-tank-master.tar.gz
Expand Down
5 changes: 4 additions & 1 deletion test/helper.fish
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ function fry_after_all -e tank_finished
end

source $fish_tank
source (dirname (status -f))/../share/fry/fry.fish

set -l fry_project_path (realpath (dirname (status -f))/..)
set fish_function_path $fry_project_path/functions $fish_function_path
source $fry_project_path/conf.d/fry.fish
6 changes: 3 additions & 3 deletions test/test_fry-use.fish
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function suite_fry-use
mkdir -p $fry_rubies/rbx-2.2.6/bin
mkdir -p $fry_rubies/rbx-2.2.6/gems/bin

fry-use rbx-2.2.6 >/dev/null
fry-use rbx-2.2.6 ^/dev/null

refute_includes $fry_rubies/ruby-2.0/bin $PATH
assert_equal $fry_rubies/rbx-2.2.6/gems/bin $PATH[1]
Expand All @@ -68,7 +68,7 @@ function suite_fry-use
stub_var fry_prepend_path 0
set fish_user_paths (stub_dir)

fry-use ruby-1.9 >/dev/null
fry-use ruby-1.9 ^/dev/null

assert_equal $fry_rubies/ruby-1.9/bin $PATH[2]
end
Expand All @@ -77,7 +77,7 @@ function suite_fry-use
stub_var fry_prepend_path 1
set fish_user_paths (stub_dir)

fry-use ruby-1.9 >/dev/null
fry-use ruby-1.9 ^/dev/null

assert_equal $fry_rubies/ruby-1.9/bin $PATH[1]
end
Expand Down

0 comments on commit 4c18d70

Please sign in to comment.