From 59ba52e2b5cd9ab06e8fe8576e06e62a70809835 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Fri, 15 Nov 2013 12:06:45 +0900 Subject: [PATCH] now shrc can be invoked as a script --- shrc | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/shrc b/shrc index d65eaff..ff12e9e 100755 --- a/shrc +++ b/shrc @@ -1,13 +1,7 @@ -#!/bin/bash +#!/bin/sh # TODO: use tput -# If not running interactively, don't do anything -alias isinteractive=false -expr "$-" : '^.*i' >/dev/null && alias isinteractive=true - -isinteractive || return - ########################################## null(){ "$@" >/dev/null 2>&1 @@ -17,11 +11,16 @@ __try_exec(){ } __match(){ - # __match str1 str2 - # return 0 if str2 is found in str1 + # __match str word + # return 0 if word is found in str expr "$1" : ".*$2.*" >/dev/null } +alias isinteractive=false +__match "$-" i >/dev/null && alias isinteractive=true +alias issourced=true +expr "$0" : "^.*shrc$" >/dev/null && alias issourced=false # invoked as script + ########################## # system type @@ -55,6 +54,18 @@ fi ################################# +if inbash +then + shrc="$BASH_SOURCE" +elif inzsh +then + shrc="$0" +fi + +dotdir="`dirname "$shrc"`" + +################################# + alias firstload=false __match "$PATH" "$HOME/.local/bin" || alias firstload=true @@ -175,6 +186,10 @@ fi ####################### +# If not running interactively, don't do anything +issourced || exit +isinteractive || return + iswindows && alias tty="echo cmd.exe" type fortune >/dev/null 2>&1 && { fortune