tidy up for public access, insert converter for repo change

This commit is contained in:
Ville Rantanen
2016-03-08 15:32:18 +02:00
parent f5d234c3ad
commit 5ead3ea01c
3 changed files with 52 additions and 11 deletions

8
README
View File

@@ -9,6 +9,14 @@ cd $( dirname $0 )/bin
(
echo Add the tools to PATH by sourcing the "rc" in this folder
echo -e "\n===== COMMANDS IN qcd_function ====="
echo -e "===================================="
grep "^function " -A 1 ../qcd_function
echo -e "\n===== COMMANDS IN bin/ ====="
echo -e "============================"
for e in *; do
test -x $e || continue
echo -e "\n===== $e =====\n"

View File

@@ -1,4 +1,5 @@
function cd_history () {
# Function that replaces "cd". It stores visited folder in ~/.bash_cdhistory
local old
local p
local b
@@ -17,6 +18,7 @@ function cd_history () {
alias cd=cd_history
function hcd() {
# History cd. Run without arguments to see list of entries, give number to change cwd.
local d
if [ -z "$1" ]
@@ -31,6 +33,7 @@ function hcd() {
}
function qcd() {
# cd command, that jumps to folders visited in the near history, or user bookmarked folders
local OPTIND
local OPTARG
local opt
@@ -156,6 +159,7 @@ Keeps a history of folders visited in ~/.bash_cdhistory
}
function whenfilechanges() {
# Run a command when file(s) time stamp changes
echo "Version: 2015-10-13"
[ -z "$2" ] && { echo 'Usage: whenfilechanges "file" "some" "command"
Follows the modification time of the "file" and runs the command
@@ -278,7 +282,7 @@ sys.stderr.write(os.path.join(pat_dir,key_match))
}
function rmv () {
#mv with rsync
# mv files/folders with rsync (shows speed and progress)
local sources
sources=()
# remove / from ends, if target is an existing folder
@@ -329,6 +333,7 @@ function ised () {
}
function foldermenu_prompt {
# Function to add in PS prompt variable, enabling foldermenu support
[ -f .foldermenu ] && {
foldermenu -lf 10 $@ || echo -n "*"
} || {
@@ -337,12 +342,10 @@ function foldermenu_prompt {
}
function _tools-update {
# update self
[[ -z "$TOOLSPATH" ]] || return
[[ -w "$TOOLSPATH" ]] || return
touch "$TOOLSPATH"/.lastupdate
[[ -w "$TOOLSPATH"/.lastupdate ]] || return
pushd "$TOOLSPATH" > /dev/null
hg pull -u 2>&1
popd > /dev/null
"$TOOLSPATH"/rc -u
}
function qbg {
@@ -360,6 +363,7 @@ function set_term_title {
}
function path_add_current {
# Add current folder to PATH
export PATH=$( echo $(pwd):$PATH | awk -F: '{for (i=1;i<=NF;i++) { if ( !x[$i]++ ) printf("%s:",$i); }}' | sed 's,:\+$,,g' )
echo PATH=$PATH
}

35
rc
View File

@@ -13,21 +13,50 @@ export PATH
function _self_update() {
touch "$TOOLSPATH"/.lastupdate
pushd "$TOOLSPATH" > /dev/null
timeout 5 hg pull -u > /dev/null 2>&1 &
[[ "$1" = "-u" ]] && {
hg pull -u
} || {
timeout 5 hg pull -u > /dev/null 2>&1
}
popd > /dev/null
}
[[ "$1" = "-u" ]] && _self_update
function _change_hg_repo() {
[[ -w "$TOOLSPATH"/.hg ]] || return
[[ -w "$TOOLSPATH"/.hg/hgrc ]] || return
grep -q moonq.kapsi.fi/repo/ "$TOOLSPATH"/.hg/hgrc && {
echo -e "Converting read only repository to bitbucket\n"
sed 's,\s*default\s*=.*moonq.kapsi.fi.*,default = https://bitbucket.org/MoonQ/tools,' "$TOOLSPATH"/.hg/hgrc \
| diff "$TOOLSPATH"/.hg/hgrc -
sed -i 's,\s*default\s*=.*moonq.kapsi.fi.*,default = https://bitbucket.org/MoonQ/tools,' "$TOOLSPATH"/.hg/hgrc
}
grep -q moonq.kapsi.fi/repoz/ "$TOOLSPATH"/.hg/hgrc && {
echo -e "Converting writable repository to bitbucket\n"
sed 's,\s*default\s*=.*moonq.kapsi.fi.*,default = ssh://hg@bitbucket.org/MoonQ/tools,' "$TOOLSPATH"/.hg/hgrc \
| diff "$TOOLSPATH"/.hg/hgrc -
echo
sed -i 's,\s*default\s*=.*moonq.kapsi.fi.*,default = ssh://hg@bitbucket.org/MoonQ/tools,' "$TOOLSPATH"/.hg/hgrc
}
}
# Update self weekly
[[ "$1" = "-u" ]] && _self_update -u
# Update self weekly,
# if folder writable, if repository, if an interactive terminal, if not updated the last week
[[ -w "$TOOLSPATH" ]] || return
[[ -w "$TOOLSPATH"/.hg ]] || return
[[ -t 0 ]] || return
[[ -t 1 ]] || return
[[ -t 2 ]] || return
[[ -f "$TOOLSPATH"/.lastupdate ]] || touch -t 0101010101 "$TOOLSPATH"/.lastupdate 2> /dev/null
[[ -w "$TOOLSPATH"/.lastupdate ]] || return
_change_hg_repo
unset -f _change_hg_repo
TOOLS_LASTUPDATE=$(( $( date +%s ) - $( stat -c %Y "$TOOLSPATH"/.lastupdate ) ))
[[ "$TOOLS_LASTUPDATE" -gt 604800 ]] && _self_update
unset TOOLS_LASTUPDATE
unset -f _self_update