diff --git a/bin/anytomobi b/bin/anytomobi old mode 100644 new mode 100755 index 08c57aa..edb90c2 --- a/bin/anytomobi +++ b/bin/anytomobi @@ -7,8 +7,7 @@ # Author: Artem Sapegin, sapegin.me # # Require: -# - KindleGen - http://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000765211 -# - Calibre - http://calibre-ebook.com/download +# - Calibre - http://calibre-ebook.com/download (install command line tools from Calibre’s settings) # # Manuals: # - http://manual.calibre-ebook.com/cli/ebook-convert.html @@ -22,23 +21,17 @@ function convert_file() { local infilename=$(basename "$1") local outfilename="${infilename%.*}.mobi" - if [[ "$intype" == "mobi" || "$intype" == "pdf" ]]; then - # Just copy MOBI and PDF files to destination directory + if [[ "$intype" == "pdf" ]]; then + # Just copy PDF files to destination directory if [[ "$outdir" != "." ]]; then cp "$infile" "$outdir/" fi return - elif [[ "$intype" == "epub" ]]; then - kindlegen "$infile" -o "$outfilename" - # kindlegen can’t save file to other directory, so we should move it - if [[ "$outdir" != "." ]]; then - mv "${infile%.*}.mobi" "$outdir/" - fi else - ebook-convert "$infile" "$outdir/$outfilename" --output-profile=kindle_pw --mobi-file-type=new \ - --mobi-ignore-margins --mobi-keep-original-images \ - --no-inline-toc --no-inline-fb2-toc --remove-paragraph-spacing \ - --change-justification=left --keep-ligatures --smarten-punctuation --pretty-print + # Convert any other format (MOBI too) to old MOBI format to force left text alignment + ebook-convert "$infile" "$outdir/$outfilename" --output-profile=kindle_pw --mobi-file-type=old \ + --mobi-ignore-margins --mobi-keep-original-images --no-inline-toc --remove-paragraph-spacing \ + --change-justification=left --keep-ligatures --smarten-punctuation --pretty-print --filter-css=color fi echo @@ -64,6 +57,6 @@ if [[ -f "$1" ]]; then elif [[ -d "$1" ]]; then convert_dir "$1" else - echo "Usage: anytomobi [destination folder]" + echo "Usage: `basename $0` [destination folder]" exit 1 fi diff --git a/includes/bash_aliases.bash b/includes/bash_aliases.bash index e9e2e2e..297dff4 100644 --- a/includes/bash_aliases.bash +++ b/includes/bash_aliases.bash @@ -17,6 +17,7 @@ alias oo="open ." alias e="subl" alias gh="github" alias +x="chmod +x" +alias g="ack -ri" # Detect which `ls` flavor is in use if ls --color > /dev/null 2>&1; then # GNU `ls` diff --git a/includes/bash_functions.bash b/includes/bash_functions.bash index 5cad0db..da59f5c 100644 --- a/includes/bash_functions.bash +++ b/includes/bash_functions.bash @@ -111,14 +111,15 @@ ssh-key() { # Create an SSH key and uploads it to the given host # Based on https://gist.github.com/1761938 -add-ssh-host() { +ssh-add-host() { username=$1 hostname=$2 identifier=$3 if [[ "$identifier" == "" ]] || [[ "$username" == "" ]] || [[ "$hostname" == "" ]]; then - echo "Usage: configure_ssh_host " + echo "Usage: ssh-add-host " else + header "Generating key..." if [ ! -f "$HOME/.ssh/$identifier.id_rsa" ]; then ssh-keygen -f ~/.ssh/$identifier.id_rsa -C "$USER $(date +'%Y/%m%/%d %H:%M:%S')" fi @@ -127,6 +128,7 @@ add-ssh-host() { echo -e "Host $identifier\n\tHostName $hostname\n\tUser $username\n\tIdentityFile ~/.ssh/$identifier.id_rsa" >> ~/.ssh/config fi + header "Uploading key..." ssh $identifier 'mkdir -p .ssh && cat >> ~/.ssh/authorized_keys' < ~/.ssh/$identifier.id_rsa.pub tput bold; ssh -o PasswordAuthentication=no $identifier true && { tput setaf 2; echo "SSH key added."; } || { tput setaf 1; echo "Failure"; }; tput sgr0 @@ -253,6 +255,27 @@ function rasterize() { fi } +# Add note to Notes.app (OS X 10.8) +# Usage: note "foo" or echo "foo" | note +function note() { + local text + if [ -t 0 ]; then # Argument + text="$1" + else # Pipe + text=$(cat) + fi + body=$(echo "$text" | sed -E 's|$|
|g') + osascript >/dev/null <