Created
April 10, 2017 16:56
-
-
Save zonuexe/cea8b771176ff3b15a87f8b0a016c028 to your computer and use it in GitHub Desktop.
TSD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (c) 2017 USAMI Kenta <tadsan@zonu.me> | |
# @author tadsan | |
# @license GPL-3.0 | |
# This program comes with ABSOLUTELY NO WARRANTY; | |
# This is free software, and you are welcome to redistribute it | |
# under certain conditions; type `tsd version' for details. | |
TSD_CMD_VER="0.0.1" | |
LAST_UPDATE="2017-04-10" | |
subcommand=$1; shift | |
tsd_local=${TSD_LOCAL:-$HOME/bin} | |
tsd_base=/home/tadsan/local/bin | |
#set -euxo pipefail | |
case $subcommand in | |
lis*|ls) | |
comm -23 <(ls -1 $tsd_base) <(ls -1 $tsd_local) | |
;; | |
al*) | |
ls -1 $tsd_base | |
;; | |
loc*) | |
ls -1 $tsd_local | |
;; | |
ini*) | |
if [[ ! -d $tsd_local ]] | |
then | |
echo + mkdir -p $tsd_local | |
mkdir -p $tsd_local | |
fi | |
if echo $PATH | grep $tsd_local > /dev/null | |
then | |
: | |
else | |
echo "環境変数 PATH を追加してね" | |
echo | |
echo " echo PATH=$tsd_local:\$PATH >> ~/.bashrc" | |
echo " echo PATH=$tsd_local:\$PATH >> ~/.zshrc" | |
echo | |
fi | |
;; | |
ins*) | |
while [ "$1" != "" ]; do | |
if [[ -f ${tsd_base}/$1 ]] | |
then | |
ln -svf ${tsd_base}/$1 ${tsd_local}/$1 | |
shift | |
else | |
echo "\"$1\" is not found" | |
exit 1 | |
fi | |
done | |
;; | |
he*) | |
echo "ヾ(〃><)ノ゙< tsd" | |
echo "usage $0 <command>" | |
echo | |
echo "tsd_local: ${tsd_local} (インストール先)" | |
echo "esa: https://pixiv.esa.io/posts/3724" | |
echo | |
echo "commands:" | |
echo " list 未インストールの実行ファイルを一覧するよ" | |
echo " all 全ての実行ファイルを一覧するよ" | |
echo " install コマンドをインストールするよ" | |
echo " local インストールされたコマンドを一覧するよ" | |
echo " init 初期化するよ" | |
echo " help ヘルプを見るよ" | |
;; | |
ver*) | |
echo "ヾ(〃><)ノ゙< TSD" Version ${TSD_CMD_VER} | |
echo "Copyright (c) 2017 USAMI Kenta <tadsan@zonu.me>" | |
echo | |
cat << EOF | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | |
EOF | |
;; | |
"") | |
if [[ ! -d $tsd_local ]] | |
then | |
echo -n "初期化するかい? [Y/n] > " | |
read input | |
input= | |
case $(echo $input | tr y Y) in | |
"" | Y) | |
$0 init | |
echo | |
;; | |
esac | |
fi | |
$0 help | |
;; | |
*) | |
echo "\"${subcommand}\" is not sub command" | |
echo | |
$0 help | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment