소스 검색

Added updating and recent files

master
= 4 년 전
부모
커밋
7921683dd7
1개의 변경된 파일39개의 추가작업 그리고 19개의 파일을 삭제
  1. +39
    -19
      mru

+ 39
- 19
mru 파일 보기

@@ -8,8 +8,10 @@ XDG_CACHE_HOME="$HOME/.cache"


init() { init() {
mkdir -p $XDG_CACHE_HOME/mru mkdir -p $XDG_CACHE_HOME/mru
file=XDG_CACHE_HOME/mru/$1
create_new "$1" create_new "$1"
mv "$file.new" "$file" mv "$file.new" "$file"
touch $XDG_CACHE_HOME/mru/$file.recent
} }


get_cache_path() { get_cache_path() {
@@ -27,19 +29,37 @@ create_new() {
-path '*Backups/my-plugins*' -o -path '*.sw[po]' \) -printf \ -path '*Backups/my-plugins*' -o -path '*.sw[po]' \) -printf \
'%TY-%Tm-%Td\t%TT\t%p\n' | sort -r > $file'.new' '%TY-%Tm-%Td\t%TT\t%p\n' | sort -r > $file'.new'
} }

update() { update() {
clean file=$XDG_CACHE_HOME/mru/$1
name="$1" name="$1"
if [ -z "$1" ]; then if [ -z "$1" ]; then name='home'; fi
name='home'
fi
create_new "$name" create_new "$name"
mv "$file.new" "$file"
rm_recent "$1"
}

# This remove duplicates by deleting files in recent from the main file
rm_recent() {
file=$XDG_CACHE_HOME/mru/$1
if [ -z "$1" ]; then file=$XDG_CACHE_HOME/mru/home; fi
while read line
do
l=$(printf "$line" | cut -f3)
if [ ! -z $l ]; then sed -i "\|.*\t.*\t$l|d" $file; fi
done <$file.recent
} }


output() { output() {
if [ -z "$1" ]; then if [ -z "$1" ]; then
cat $XDG_CACHE_HOME/mru/home; else cat "$XDG_CACHE_HOME/mru/$1"; file1="$XDG_CACHE_HOME/mru/home.recent"; file2="$XDG_CACHE_HOME/mru/home"
else
file1="$XDG_CACHE_HOME/mru/$1.recent"; file2="$XDG_CACHE_HOME/mru/$1"
fi fi

cat $file1; printf "\n"; cat $file2
} }


list() { list() {
@@ -48,25 +68,26 @@ list() {


insert() { insert() {
if [ -z "$1" ]; then printf "No path given\n" 1>&2; exit; fi if [ -z "$1" ]; then printf "No path given\n" 1>&2; exit; fi
cache_name=${1+'home'} cache_name=$2
if [ -z "$2" ]; then cache_name=home; fi
cache_path=$(get_cache_path "$cache_name") cache_path=$(get_cache_path "$cache_name")

file_path=$(realpath "$1") file_path=$(realpath "$1")

if [ -e "$file_path" ]; then if [ -e "$file_path" ]; then
# sed "0,\|.*\t.*\t$file_path|s|||" $XDG_CACHE_HOME/mru/$cache_name sed -i -e "0,\|.*\t.*\t$file_path|d" $XDG_CACHE_HOME/mru/$cache_name.recent
sed -e "0,\|.*\t.*\t$file_path|d" -e "1s;^;$(date '+%Y-%m-%d%t%T')\t$file_path\n;" <$XDG_CACHE_HOME/mru/$cache_name \ if [ -s $XDG_CACHE_HOME/mru/$cache_name.recent ]; then
>$XDG_CACHE_HOME/mru/$cache_name.insert$$ echo "sed starts$(date '+%Y-%m-%d%t%T')\t$file_path\n"
mv $XDG_CACHE_HOME/mru/$cache_name.insert$$ $XDG_CACHE_HOME/mru/$cache_name sed -i "1i$(date '+%Y-%m-%d%t%T')\t$file_path" $XDG_CACHE_HOME/mru/$cache_name.recent
else echo 'sed ends'
sed "0,\|.*\t.*\t$file_path|d" <$XDG_CACHE_HOME/mru/$cache_name \ else
>$XDG_CACHE_HOME/mru/$cache_name.insert$$ printf "$(date '+%Y-%m-%d%t%T')\t$file_path" >$XDG_CACHE_HOME/mru/$cache_name.recent
mv $XDG_CACHE_HOME/mru/$cache_name.insert$$ $XDG_CACHE_HOME/mru/$cache_name fi
fi


if [ ! -z $file_path ]; then
sed -i "0,\|.*\t.*\t$file_path|d" $XDG_CACHE_HOME/mru/$cache_name
fi fi
}


clean() {
rm $XDG_CACHE_HOME/mru/*.{insert,new}*
} }


case "$1" in case "$1" in
@@ -75,5 +96,4 @@ case "$1" in
output) output "$2";; output) output "$2";;
list) list "$2";; list) list "$2";;
insert) insert "$2" "$3";; insert) insert "$2" "$3";;
clean) clean;;
esac esac

||||||
x
 
000:0
불러오는 중...
취소
저장