- Convert pafile and pafinder aliases to shell functions with better parameter handling - Make pafile query parameter optional for interactive document selection - Add patag function for hash-separated multi-tag addition (e.g., patag "tag1#tag2" query) - Add paopen alias for quick document opening - Update README to document all papis workflow shortcuts and functions - Fix deprecated zsh initExtra to initContent 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
133 lines
3.7 KiB
Nix
133 lines
3.7 KiB
Nix
{ pkgs, ... }:
|
|
|
|
{
|
|
# Papis configuration
|
|
home.file."Library/Application Support/papis/config".text = ''
|
|
[settings]
|
|
default-library = main
|
|
editor = nvim
|
|
opentool = open
|
|
file-browser = open
|
|
|
|
# Document management
|
|
ref-format = {doc[author]}{doc[year]}
|
|
|
|
# Search and display
|
|
sort-field = year
|
|
sort-reverse = True
|
|
match-format = {doc[tags]}{doc[author]}{doc[title]}{doc[year]}
|
|
|
|
# Database and storage
|
|
database-backend = papis
|
|
use-git = False
|
|
|
|
# Interface
|
|
fzf-binary = fzf
|
|
picktool = fzf
|
|
|
|
[main]
|
|
dir = ~/Documents/Library/papis
|
|
|
|
# Local configuration for the main library
|
|
local-config-file = .papisrc
|
|
'';
|
|
|
|
# Create the papis library directory
|
|
home.activation.createPapisDir = ''
|
|
mkdir -p ~/Documents/Library/papis
|
|
'';
|
|
|
|
# Papis bibliography template
|
|
home.file."Library/Application Support/papis/templates/bibitem.template".text = ''
|
|
{doc[title]} ({doc[year]}). {doc[author]}.
|
|
Venue: {doc[journal]} {doc[booktitle]} {doc[eprinttype]} {doc[eprint]} {doc[eventtitle]}
|
|
Tags: {doc[tags]}
|
|
URL: {doc[url]}
|
|
---
|
|
'';
|
|
|
|
# Shell aliases for papis workflow
|
|
programs.zsh.shellAliases = {
|
|
# Bibliography formatting
|
|
pals = "papis list --template \"$HOME/Library/Application Support/papis/templates/bibitem.template\"";
|
|
|
|
# File operations
|
|
paurl = "papis addto -u";
|
|
|
|
# Open documents
|
|
paopen = "papis open";
|
|
};
|
|
|
|
# Shell functions for papis workflow
|
|
programs.zsh.initContent = ''
|
|
# Papis finder function - open document directory in Finder with query support
|
|
pafinder() {
|
|
local result=$(papis list "$@" | head -1)
|
|
if [ -n "$result" ]; then
|
|
open -R "$result"
|
|
else
|
|
echo "No documents found"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Papis add file function - add file to existing document with proper parameter handling
|
|
pafile() {
|
|
if [ $# -lt 1 ]; then
|
|
echo "Usage: pafile <filename> [query]"
|
|
echo "Example: pafile paper.pdf # Interactive selection"
|
|
echo "Example: pafile paper.pdf \"einstein relativity\" # Direct match"
|
|
echo "Example: pafile /path/to/paper.pdf \"quantum\" # Absolute path"
|
|
return 1
|
|
fi
|
|
|
|
local filename="$1"
|
|
shift # Remove first argument
|
|
local query="$*" # All remaining arguments as query (empty if none)
|
|
|
|
# Check if filename is absolute path or relative to Downloads
|
|
if [[ "$filename" == /* ]]; then
|
|
# Absolute path
|
|
if [ -n "$query" ]; then
|
|
papis addto -f "$filename" "$query"
|
|
else
|
|
papis addto -f "$filename"
|
|
fi
|
|
else
|
|
# Relative to Downloads
|
|
if [ -n "$query" ]; then
|
|
papis addto -f "$HOME/Downloads/$filename" "$query"
|
|
else
|
|
papis addto -f "$HOME/Downloads/$filename"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Papis tag function - add multiple tags using hash-separated format
|
|
patag() {
|
|
if [ $# -ne 2 ]; then
|
|
echo "Usage: patag \"tag1#tag2#tag3\" <query>"
|
|
echo "Example: patag \"materials#ai4science\" amorphous"
|
|
echo "Example: patag \"quantum#computing\" \"author:einstein\""
|
|
return 1
|
|
fi
|
|
|
|
local tags_string="$1"
|
|
local query="$2"
|
|
|
|
# Split tags by # and build --add arguments
|
|
local add_args=""
|
|
IFS='#' read -ra tags <<< "$tags_string"
|
|
for tag in "${tags[@]}"; do
|
|
# Trim whitespace and add to arguments
|
|
tag=$(echo "$tag" | xargs)
|
|
if [ -n "$tag" ]; then
|
|
add_args="$add_args --add \"$tag\""
|
|
fi
|
|
done
|
|
|
|
# Execute the papis tag command
|
|
eval "papis tag $add_args \"$query\""
|
|
}
|
|
'';
|
|
}
|