Skip to content
Open
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
21 changes: 18 additions & 3 deletions j.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

j() {
local datafile=$HOME/.j
exec 9>$HOME/.j.lock
flock --timeout 5 9
if [ "$1" = "--add" ]; then
shift
# $HOME isn't worth matching
[ "$*" = "$HOME" ] && return
if [ "$*" = "$HOME" ]
then
flock -u 9
return
fi
awk -v q="$*" -v t="$(date +%s)" -F"|" '
BEGIN { l[q] = 1; d[q] = t }
$2 >= 1 {
Expand Down Expand Up @@ -36,11 +42,20 @@ j() {
' $datafile 2>/dev/null
else
# list/go (must set $JPY)
[ -f "$JPY" ] || return
if ! [ -f "$JPY" ]
then
flock -u 9
return
fi
cd="$($JPY -f $datafile $*)"
[ -z "$cd" -o "$cd" = "$PWD" ] && return
if [ -z "$cd" -o "$cd" = "$PWD" ]
then
flock -u 9
return
fi
cd "$cd"
fi
flock -u 9
}
# tab completion (only works in bash for now)
[ "$SHELL" = "/bin/bash" ] && complete -C 'j --complete "$COMP_LINE"' j
Expand Down