Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
path = modules/z
url = https://github.com/rupa/z.git
ignore = dirty
[submodule "modules/dotly_marketplace"]
path = modules/dotly_marketplace
url = https://github.com/gtrabanco/dotly_marketplace
branch = master
74 changes: 74 additions & 0 deletions dotfiles_template/scripts/surprise/contributors
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

source "$DOTLY_PATH/scripts/core/_main.sh"

##? Show the contributors list with their avatars
##?
##?
##? Usage:
##? contributors -h | --help
##? contributors -v | --version
##? contributors
##?
##? Options:
##? -h --help Show this help
##? -v --version Show the program version
##?
##? Author:
##? Gabriel Trabanco Llano <gtrabanco@users.noreply.github.com>
docs::parse "$@"

SCRIPT_NAME="dot surprise contributors"
SCRIPT_VERSION="1.0.0"

# Print name and version
if $version; then
output::write "$SCRIPT_NAME v$SCRIPT_VERSION"
exit
fi

# Here begin your script

if ! platform::command_exists catimg; then
output::write "Installing catimg"
$(echo "$DOTLY_PATH/bin/dot package install catimg") | log::file "Installing catimg"
echo
fi

# Some vars
TMP_FILE="/tmp/dotly/contributors.json"
TMP_AVATARS="$(dirname $TMP_FILE)/avatars"

# Creating dirs
#mkdir -p "$(dirname $TMP_FILE)"
#mkdir -p "$TMP_AVATARS"

# Download JSON if not downloaded
if [[ ! -f "$TMP_FILE" ]]; then
curl -s --create-dirs --output "$TMP_FILE" \
-H "Accept: application/vnd.github.v3+json" \
'https://api.github.com/repos/codelytv/dotly/contributors'
fi


for index in $(cat $TMP_FILE | jq 'keys | .[]' ); do
#[ -z $index ] && continue
login="$(cat $TMP_FILE | jq -r ".[$index].login")"
avatar_url="$(cat $TMP_FILE | jq -r ".[$index].avatar_url")"
avatar_file="$TMP_AVATARS/$login.jpg"
contributions="$(cat $TMP_FILE | jq -r ".[$index].contributions")"
[ ! -f $avatar_file ] && curl -s --create-dirs --output "$avatar_file" "$avatar_url"

# Formatting stuff
center_str_wl="$(( (15 - ((${#login}+1)/2)) ))"

# Image
catimg -w 60 "$avatar_file"

# Text
printf "%${center_str_wl}s"
output::write "$login"
echo
done

output::write "Thank you all. CodelyTV"
1 change: 1 addition & 0 deletions dotfiles_template/shell/aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ alias ll="ls -l"
alias la="ls -la"
alias ~="cd ~"
alias dotfiles="cd '$DOTFILES_PATH'"
alias dotly_dev='eval $(dot dotly dev path)'

# Git
alias gaa="git add -A"
Expand Down
1 change: 1 addition & 0 deletions modules/dotly_marketplace
Submodule dotly_marketplace added at 854e6a
76 changes: 76 additions & 0 deletions scripts/dotly/create
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash

source "$DOTLY_PATH/scripts/core/_main.sh"
source "$DOTLY_PATH/scripts/dotly/helpers/templating.sh"

SCRIPT_NAME="dot dotly create"
SCRIPT_VERSION="1.0.0"
SCRIPT_TEMPLATE="$DOTLY_PATH/scripts/dotly/helpers/script-template"

##? Dotly script creator
##?
##?
##? Usage:
##? create -h | --help
##? create -v | --version
##? create [-s|--sample] <context> <script_name> [<script_description>...]
##?
##? Options:
##? -h --help Show this help
##? -v --version Show the program version
##? -s --sample Create a script using more complete example with some comments.
##? useful if it is your first script. Anyway you can see more help
##? in the docopt website: http://docopt.org
##?
##? Author:
##? Gabriel Trabanco <https://keybase.io/gtrabanco>
##?
docs::parse "$@"

# Print name and version
if $version; then
output::write "$SCRIPT_NAME v$SCRIPT_VERSION"
exit
fi

# Script part
# Variables for the script
author="$(git config --global --get user.name)"
email="$(git config --global --get user.email)"
description="${script_description[@]:-You should descrive your command}"

# Path variables
script_path="$DOTFILES_PATH/scripts/$context"
script_filepath=""$script_path/$script_name""

# Which template to use
if $sample; then
SCRIPT_TEMPLATE="$SCRIPT_TEMPLATE-more"
fi

# Create the script context (folder)
mkdir -p $script_path

if [[ -d "$DOTFILES_PATH/scripts/$context" ]]; then
output::solution "$script_path were created or exists previously"
fi

if [[ -f $script_filepath ]]; then
output::question "The script exists, do you want to delete it and create a empty script? [y/N]" "SCRIPT_EXISTS_QUESTION"
SCRIPT_EXISTS_QUESTION=${SCRIPT_EXISTS_QUESTION:-"N"}
if [[ "$SCRIPT_EXISTS_QUESTION" =~ ^[Nn] ]]; then
output::error "The script name \"$script_name\" exists in context \"$context\" and user refuse to recreate the script"
output::write "Provide a different name for the script or context."
exit 1
fi
fi

cp "$SCRIPT_TEMPLATE" "$script_filepath"
dotly::apply_templating "$script_filepath" "$context" "$author" "$email" "$description"
chmod u+x "$script_filepath"

output::solution "The script '$script_name' where successfully created."
output::write ""
output::write "You can access the scipt with your favorite editor by executing:"
output::write "\$EDITOR \"\$DOTFILES_PATH/scripts/$context/$script_name\""
output::empty_line
28 changes: 28 additions & 0 deletions scripts/dotly/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

source "$DOTLY_PATH/scripts/core/_main.sh"

##? Adapt the current terminal to use develop dotly
##?
##? Usage:
##? dev path [<new_dotly_path>]
##? dev dotfiles [<new_dotfiles_path>]
docs::parse "$@"

case $1 in
"path")
echo "export DOTLY_PATH='${new_dotly_path:-$(pwd)}'"
;;
"dotfiles")
echo "export DOTFILES_PATH='${new_dotfiles_path:-$(pwd)}'"
;;
"both")
echo "export DOTLY_PATH='${new_dotly_path:-$(pwd)}'"
echo "export DOTFILES_PATH='${new_dotfiles_path:-$(pwd)}'"
;;
*)
output::write 'Use "dotly_dev" alias in your dotly development folder to"
output::write "test the dotly stuff you develop 🤘'
exit 1
;;
esac
36 changes: 36 additions & 0 deletions scripts/dotly/helpers/script-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

source "$DOTLY_PATH/scripts/core/_main.sh"

##? XXX_SCRIPT_DESCRIPTION_XXX
##?
##?
##? Usage:
##? XXX_SCRIPT_NAME_XXX [-h | --help]
##? XXX_SCRIPT_NAME_XXX [-v | --version]
##?
##? Options:
##? -h --help Show this help
##? -v --version Show the program version
##?
##? Author:
##? XXX_SCRIPT_AUTHOR_XXX <XXX_SCRIPT_AUTHOR_EMAIL_XXX>
docs::parse "$@"

SCRIPT_NAME="dot XXX_SCRIPT_CONTEXT_XXX XXX_SCRIPT_NAME_XXX"
SCRIPT_VERSION="1.0.0"

# Print name and version
if $version; then
output::write "$SCRIPT_NAME v$SCRIPT_VERSION"
exit
fi

# Here begin your script

case $1 in
# Any subcommand should be here
*)
exit 1
;;
esac
47 changes: 47 additions & 0 deletions scripts/dotly/helpers/script-template-more
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

source "$DOTLY_PATH/scripts/core/_main.sh"

##? XXX_SCRIPT_DESCRIPTION_XXX
##?
##?
##? Usage:
##? XXX_SCRIPT_NAME_XXX [-h | --help]
##? XXX_SCRIPT_NAME_XXX [-v | --version]
##? XXX_SCRIPT_NAME_XXX -c | --custom-option
##? XXX_SCRIPT_NAME_XXX subcommand <example_variable> [<example_optional_variable>...]
##?
##? Options:
##? -h --help Show this help
##? -v --version Show the program version
##? -c --custom-option With two or more spaces you can add some help
##? subcomand <example_variable> [<example_optional_variable>...] Also provide a help with subcommand
##? This text will be printed as well when you call -h or --help option
##?
##? Author:
##? XXX_SCRIPT_AUTHOR_XXX <XXX_SCRIPT_AUTHOR_EMAIL_XXX>

# Options part its important because assign short and long version of the params
docs::parse "$@"

SCRIPT_NAME="dot XXX_SCRIPT_CONTEXT_XXX XXX_SCRIPT_NAME_XXX"
SCRIPT_VERSION="1.0.0"

# Print name and version
if $version; then
output::write "$SCRIPT_NAME v$SCRIPT_VERSION"
exit
fi

# Here begin your script

case $1 in
"subcommand")
echo "This case is optional and only useful if you want to implement subcommands"
echo "The example repeteable variable value is \"${example_variable[@]}\""
echo "The optional variable value is \"${example_optional_variable:-no value provided}\""
;;
*)
exit 1
;;
esac
15 changes: 15 additions & 0 deletions scripts/dotly/helpers/templating.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This is a renamed copy of dotfiles::apply_templating
# from Rafa Gomez original dotly creator
dotly::apply_templating() {
local script_filepath="$1"
local script_context="$2"
local script_author="$3"
local script_email="$4"
local script_description="${@:5}"

sed -i -e "s|XXX_SCRIPT_DESCRIPTION_XXX|$script_description|g" "$script_filepath"
sed -i -e "s|XXX_SCRIPT_AUTHOR_EMAIL_XXX|$script_email|g" "$script_filepath"
sed -i -e "s|XXX_SCRIPT_AUTHOR_XXX|$script_author|g" "$script_filepath"
sed -i -e "s|XXX_SCRIPT_NAME_XXX|$(basename $script_filepath)|g" "$script_filepath"
sed -i -e "s|XXX_SCRIPT_CONTEXT_XXX|$script_context|g" "$script_filepath"
}
75 changes: 75 additions & 0 deletions scripts/dotly/install-remote
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash

source "$DOTLY_PATH/scripts/core/_main.sh"

SCRIPT_NAME="dot dotly install-remote"
SCRIPT_VERSION="1.0.0"

# Save current working directory to return user there
STARTING_DIRECTORY="$(pwd)"
LS_BIN="$(which ls)"
TAIL_BIN="$(which tail)"
CURL_BIN="$(which curl)"
MKDIR_BIN="$(which mkdir)"
CHMOD_BIN="$(which chmod)"

##? Install remote context or script in your $DOTFILES_PATH from url. It
##? must be the url to the raw file.
##? If you fill the last param <script_name>, the remote file name will be
##? omited and renamed in your $DOTFILES_PATH/scripts/<context> folder
##?
##? Script information:
##?
##?
##? Usage:
##? install-remote <context> <script_raw_url> [<script_name>]
##?
##? Options:
##?
##? Author:
##? Gabriel Trabanco Llano <gtrabanco@users.noreply.github.com>
docs::parse "$@"

# Print name and version
if $version; then
output::write "$SCRIPT_NAME v$SCRIPT_VERSION"
exit
fi

# Script part

# Script name if provided if not with downloaded name
[[ ! -z $script_name ]] && script_name_args="-o $script_name" || script_name_args=${script_name:-"-O"}

# Download command
download_command="$CURL_BIN -k -L -f -q $script_name_args"

# Scripts context directory
dotfiles_context="$DOTFILES_PATH/scripts/$context"

# Create context directory and move to it
$MKDIR_BIN -p $dotfiles_context
cd $dotfiles_context

# Download the script
output::write "Downloading the script ⚡️"
$(echo $download_command "$script_raw_url")
if [ ! $? ] ; then
if [ ! $($LS_BIN -A "$dotfiles_context") ]; then
echo "El context $dotfiles_context esta vacio"
fi
fi

# Getting the name
script_name="$($LS_BIN -Art | $TAIL_BIN -n 1)"

# Applying execution rights
$CHMOD_BIN u+x $dotfiles_context/$script_name

# How to use it :)
echo
output::solution "The script was successfully added 😀"
output::write "You can execute the script now with:"
output::write "dot $context $script_name"

cd "$STARTING_DIRECTORY"