Permalink
Browse files

Update internal API and rename sh files to bash for clarity.

  • Loading branch information...
1 parent 060dc5f commit 2c3f08d089cd4389f64579860f67a284c2990400 @zeekay committed Apr 29, 2014
View
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-source "$(dirname "${BASH_SOURCE[0]}")/../src/init.sh"
+source "$(dirname "${BASH_SOURCE[0]}")/../src/init.bash"
load cli
@@ -24,21 +24,18 @@ FINAL_ELLIPSIS_PATH=${ELLIPSIS_PATH:-$HOME/.ellipsis}
ELLIPSIS_PATH="$tmp_dir/ellipsis"
# Initialize ellipsis.
-source $tmp_dir/ellipsis/src/init.sh
+source $tmp_dir/ellipsis/src/init.bash
# Load modules.
load ellipsis
load fs
-load git
load os
-load pkg
load registry
-load utils
ELLIPSIS_PATH="$FINAL_ELLIPSIS_PATH"
# Backup existing ~/.ellipsis if necessary and move project into place.
-ellipsis.backup $ELLIPSIS_PATH
+fs.backup $ELLIPSIS_PATH
mv $tmp_dir/ellipsis $ELLIPSIS_PATH
# Clean up (only necessary on cygwin, really).
View
@@ -1,7 +1,7 @@
EOF
-# shim for ellipsis install.sh
+# shim for ellipsis install.bash
#
# This is used on ellipsis.sh to bootstrap the full installer, which you
# otherwise can't curl and pipe to sh (as it requires bash). Not meant to be
@@ -18,7 +18,7 @@ for dep in $deps; do
done
# Download full installer and execute with bash
-curl -sL https://raw.githubusercontent.com/zeekay/ellipsis/master/scripts/install.sh > install-$$.sh
+curl -sL https://raw.githubusercontent.com/zeekay/ellipsis/master/scripts/install.bash > install-$$.sh
bash install-$$.sh
# Clean up
@@ -1,13 +1,7 @@
-#!/usr/bin/env bash
+# cli.bash
#
-# cli.sh
# Command line interface for ellipsis.
-# Initialize ourselves if we haven't yet.
-if [[ $ELLIPSIS_INIT -ne 1 ]]; then
- source "$(dirname "${BASH_SOURCE[0]}")"/init.sh
-fi
-
load ellipsis
load registry
@@ -1,13 +1,7 @@
-#!/usr/bin/env bash
+# ellipsis.bash
#
-# ellipsis.sh
# Core ellipsis interface.
-# Initialize ourselves if we haven't yet.
-if [[ $ELLIPSIS_INIT -ne 1 ]]; then
- source "$(dirname "${BASH_SOURCE[0]}")/init.sh"
-fi
-
load fs
load git
load pkg
@@ -41,18 +35,18 @@ ellipsis.install() {
case "$1" in
http:*|https:*|git:*|ssh:*)
PKG_NAME="$(echo $1 | rev | cut -d '/' -f 1 | rev)"
- PKG_PATH="$(pkg.name_to_path $PKG_NAME)"
+ PKG_PATH="$(pkg.path_from_name $PKG_NAME)"
PKG_URL="$1"
;;
*/*)
PKG_USER=$(echo $1 | cut -d '/' -f1)
PKG_NAME=$(echo $1 | cut -d '/' -f2)
- PKG_PATH="$(pkg.name_to_path $PKG_NAME)"
+ PKG_PATH="$(pkg.path_from_name $PKG_NAME)"
PKG_URL="$ELLIPSIS_PROTO://github.com/$PKG_USER/$PKG_NAME"
;;
*)
PKG_NAME="$1"
- PKG_PATH="$(pkg.name_to_path $PKG_NAME)"
+ PKG_PATH="$(pkg.path_from_name $PKG_NAME)"
PKG_URL="$ELLIPSIS_PROTO://github.com/$ELLIPSIS_USER/$PKG_NAME"
;;
esac
@@ -81,7 +75,7 @@ ellipsis.unlink() {
}
# List installed packages.
-ellipsis.list() {
+ellipsis.installed() {
if utils.cmd_exists column; then
ellipsis.each pkg.run_hook list | column -t -s $'\t'
else
@@ -187,7 +181,7 @@ EOF
git init
git add README.md ellipsis.sh
git commit -m "Initial commit"
- echo new package created at ${path.relative_path $PKG_PATH}
+ echo new package created at ${path.relative_to_home $PKG_PATH}
}
# Edit ellipsis.sh for package, or open ellipsis dir in $EDITOR.
@@ -202,6 +196,17 @@ ellipsis.edit() {
fi
}
+# List all symlinks (slightly optimized over calling pkg.list_symlinks for each
+# package.
+ellipsis._list_symlink_mappings() {
+ for file in $(fs.list_symlinks); do
+ local link="$(readlink $file)"
+ if [[ "$link" == $ELLIPSIS_PATH* ]]; then
+ echo "$(path.relative_to_packages $link) -> $(path.relative_to_home $file)";
+ fi
+ done
+}
+
# List all symlinks, or just symlinks for a given package
ellipsis.symlinks() {
if [ $# -eq 1 ]; then
@@ -210,17 +215,17 @@ ellipsis.symlinks() {
pkg.del
else
if utils.cmd_exists column; then
- ellipsis.list_symlink_mappings | sort | column -t
+ ellipsis._list_symlink_mappings | sort | column -t
else
- ellipsis.list_symlink_mappings | sort
+ ellipsis._list_symlink_mappings | sort
fi
fi
}
# List broken symlinks in ELLIPSIS_HOME
ellipsis.broken() {
for file in $(find -L $ELLIPSIS_HOME -maxdepth 1 -type l); do
- echo "$(utils.strip_packages_dir $(readlink $file)) -> $(path.relative_path $file)";
+ echo "$(path.relative_to_packages $(readlink $file)) -> $(path.relative_to_home $file)";
done
}
View
@@ -1,13 +1,7 @@
-#!/usr/bin/env bash
+# fs.bash
#
-# fs.sh
# Files/path functions used by ellipis.
-# Initialize ourselves if we haven't yet.
-if [[ $ELLIPSIS_INIT -ne 1 ]]; then
- source "$(dirname "${BASH_SOURCE[0]}")"/init.sh
-fi
-
# return true if folder is empty
fs.folder_empty() {
if [ "$(find $1 -prune -empty)" ]; then
@@ -45,18 +39,6 @@ fs.list_symlinks() {
find "${1:-$ELLIPSIS_HOME}" -maxdepth 1 -type l
}
-# List all symlinks (slightly optimized over calling pkg.list_symlinks for each
-# package.
-# List all symlinks and files they resolve to
-fs.list_symlink_mappings() {
- for file in $(fs.list_symlinks); do
- local link="$(readlink $file)"
- if [[ "$link" == $ELLIPSIS_PATH* ]]; then
- echo "$(utils.strip_packages_dir $link) -> $(path.relative_path $file)";
- fi
- done
-}
-
# backup existing file, ensuring you don't overwrite existing backups
fs.backup() {
local original="$1"
@@ -1,15 +1,11 @@
-#!/usr/bin/env bash
+# git.bash
#
-# git.sh
# Assorted git utility functions. These functions all require us to cd into the
# git repo we want to operate on first. These exist mostly for aesthetic
# reasons, i.e., pretty output in the various ellipsis commands and can be used
# by package authors for consistency with them.
-# Initialize ourselves if we haven't yet.
-if [[ $ELLIPSIS_INIT -ne 1 ]]; then
- source "$(dirname "${BASH_SOURCE[0]}")"/init.sh
-fi
+load pkg
# Clone a Git repo.
git.clone() {
@@ -1,14 +1,8 @@
-#!/usr/bin/env bash
+# github.bash
#
-# github.sh
# Assorted functions for querying Github for package information and formatting
# responses.
-# Initialize ourselves if we haven't yet.
-if [[ $ELLIPSIS_INIT -ne 1 ]]; then
- source "$(dirname "${BASH_SOURCE[0]}")"/init.sh
-fi
-
# Search epmi org on Github for a given package.
github.search() {
curl -s https://api.github.com/search/repositories\?q\=$1+user:epmi+fork:only
@@ -1,13 +1,7 @@
-#!/usr/bin/env bash
+# hooks.bash
#
-# hooks.sh
# Default hooks used by ellipsis when package hooks are undefined.
-# Initialize ourselves if we haven't yet.
-if [[ $ELLIPSIS_INIT -ne 1 ]]; then
- source "$(dirname "${BASH_SOURCE[0]}")"/init.sh
-fi
-
load fs
load pkg
load utils
@@ -26,7 +20,7 @@ hooks.unlink() {
# Remove package's symlinks then remove package.
hooks.uninstall() {
- pkg.run_hook pkg.unlink
+ pkg.run_hook unlink
rm -rf $PKG_PATH
}
@@ -35,28 +29,28 @@ hooks.symlinks() {
echo -e "\033[1m$PKG_NAME\033[0m"
if utils.cmd_exists column; then
- pkg.symlinks_mappings | sort | column -t
+ pkg.list_symlink_mappings | sort | column -t
else
- pkg.symlinks_mappings | sort
+ pkg.list_symlink_mappings | sort
fi
}
# Do git pull from package
hooks.pull() {
- pkg.run git.pull
+ git.pull
}
# Do git push from package
hooks.push() {
- pkg.run git.push
+ git.push
}
# List repo status.
hooks.list() {
- pkg.run git.list
+ git.list
}
# List repo status if it's changed and show git diffstat.
hooks.status() {
- pkg.run git.status
+ git.status
}
@@ -1,13 +1,10 @@
-#!/usr/bin/env bash
+# init.bash
#
-# init.sh
-# Setup initial globals and load function used to source other modules.
+# Setup initial globals and load function used to source other modules. This
+# file must be sourced before any others.
-# These globals can be set by a user to use a custom ellipsis fork/set of packages/etc
-
-# git config returns 1 if key isn't found, so we pipe to cat to squash that in
-# the case it's not-defined.
if [[ -z "$ELLIPSIS_USER" ]]; then
+ # Pipe to cat to squash git config's exit code 1 in case of missing key.
GITHUB_USER=$(git config github.user | cat)
ELLIPSIS_USER=${GITHUB_USER:-zeekay}
fi
@@ -36,7 +33,7 @@ load() {
# Mark this module as loaded, prevent infinite recursion, ya know...
eval "$loaded=1"
- source $ELLIPSIS_PATH/src/$1.sh
+ source $ELLIPSIS_PATH/src/$1.bash
fi
}
@@ -1,6 +1,5 @@
-#!/usr/bin/env bash
+# log.bash
#
-# log.sh
# Logging utilities.
log.info() {
@@ -1,9 +1,7 @@
-#!/usr/bin/env bash
+# os.bash
#
-# os.sh
# Platform detection and OS functions.
-# platform detection
os.platform() {
case "$(uname | tr '[:upper:]' '[:lower:]')" in
cygwin*)
@@ -1,13 +1,7 @@
-#!/usr/bin/env bash
+# path.bash
#
-# path.sh
# Pathname functions used by ellipis.
-# Initialize ourselves if we haven't yet.
-if [[ $ELLIPSIS_INIT -ne 1 ]]; then
- source "$(dirname "${BASH_SOURCE[0]}")"/init.sh
-fi
-
# dunno how this isn't part of POSIX
path.abs_path() {
echo $(cd $(dirname "$1"); pwd)/$(basename "$1")
@@ -26,21 +20,11 @@ path.is_path() {
}
# return path to file relative to HOME (if possible)
-path.relative_path() {
+path.relative_to_home() {
echo ${1/$HOME/\~}
}
# Path relative to packagesreturn path to file in packages dir
-path.relative_packages_path() {
+path.relative_to_packages() {
echo ${1/$ELLIPSIS_PATH\/packages\//}
}
-
-# Convert package name to path.
-path.pkg_path_from_name() {
- echo "$ELLIPSIS_PATH/packages/$1"
-}
-
-# Convert package path to name, stripping any leading dots.
-path.pkg_name_from_path() {
- echo ${1##*/} | sed -e "s/^\.//"
-}
Oops, something went wrong.

0 comments on commit 2c3f08d

Please sign in to comment.