Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Script] pdf-cache.sh - stores symlinks of your pdf in .pdf
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
Ashii
n00b
n00b


Joined: 25 Jan 2012
Posts: 2

PostPosted: Wed Jan 25, 2012 8:48 pm    Post subject: [Script] pdf-cache.sh - stores symlinks of your pdf in .pdf Reply with quote

Quote:
http://pastebin.com/jW2XSP42


Code:
    #!/bin/bash
    # creates
    # ~/.pdf              <-- your pdf symlinks are here
    # ~/.pdfcache/cache   <-- list of pdf files
    # search_dir = <dir to scan for pdf>
    # note; I made it delete the directory, before the scan, so it only stores one search
     
    # TODO: for later version
    # 21:24:10 <apus> perhaps it would be a good idea to skip hidden directories and files as well ... don't think they should be cached: \( ! -regex '.*/\..*' \)
     
     
    search_dir=$HOME
    echo "Looking for pdf in: $search_dir"
    if [ -d ~/.pdfcache ] ; then
        rm -Rf ~/.pdf
        find $search_dir -iname "*.pdf" > ~/.pdfcache/cache
    else
        mkdir ~/.pdf
        mkdir ~/.pdfcache
        # ignores the directory .pdf under $HOME
        find $search_dir -name ".pdf" -prune -o -type f -print | grep .pdf$
    fi
     
    mkdir ~/.pdf
    while read -r line; do ln -s "$line" "/home/$USER/.pdf/${line##*/}"
    done < $HOME/.pdfcache/cache


I was missing a bookshelf for all my pdf files, so I symlinked them all to ~/.pdf now its all pretty and sorted.
Back to top
View user's profile Send private message
Ashii
n00b
n00b


Joined: 25 Jan 2012
Posts: 2

PostPosted: Wed Jan 25, 2012 8:57 pm    Post subject: cleaned up version Reply with quote

Quote:
http://pastebin.com/3ezWj4aX


Code:
    #!/bin/bash
    # creates ~/.pdf
    # search_dir = <dir to scan for pdf>
    # note: the symlinks in .pdf are removed at each run
     
    search_dir="$HOME"
    echo "Looking for pdf in: $search_dir"
     
    if [[ ! -d "$HOME"/.pdf ]] ; then
      if ! mkdir "$HOME"/.pdf; then
        echo "Aborting. Couldn't create directory .pdf."
        exit 1
      fi
    else
      # clean up directory .pdf[/quote]
      rm -rf "$HOME"/.pdf/*
    fi
     
    while IFS= read -rd '' line; do
      ln -s "$line" "$HOME/.pdf/${line##*/}"
    done < <(find "$search_dir" -regex '.*/\..*' -prune -o -type f -iname '*.pdf' -print0)


credit to apus
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2971
Location: Germany

PostPosted: Wed Jan 25, 2012 9:01 pm    Post subject: Reply with quote

Interesting.

Code:
mkdir ~/.pdf/
rm ~/.pdf/*
find ~ -type f -name "*.pdf" -print0 | xargs -0 -I {} -n 1 ln -bs {} ~/.pdf/
Back to top
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Wed Jan 25, 2012 11:35 pm    Post subject: Reply with quote

frostschutz wrote:
Interesting.

Code:
mkdir ~/.pdf/
rm ~/.pdf/*
find ~ -type f -name "*.pdf" -print0 | xargs -0 -I {} -n 1 ln -bs {} ~/.pdf/
Why xargs and not directly `find`'s "-exec"?
_________________
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2971
Location: Germany

PostPosted: Thu Jan 26, 2012 6:56 pm    Post subject: Reply with quote

No reason. I just somehow got stuck on xargs because I don't always use find as a data source for filename lists.

Here's to without xargs:

Code:
find ~ -type f -name "*.pdf" -exec ln -bs {} ~/.pdf/ \;
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum