save
This commit is contained in:
parent
7360824eab
commit
368ebfaba2
6 changed files with 147 additions and 0 deletions
28
bin/apas
Executable file
28
bin/apas
Executable file
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
function lhash {
|
||||
echo -n "${1}" | openssl dgst -sha512 | cut -d' ' -f2 | openssl dgst -md5 | cut -d' ' -f2
|
||||
}
|
||||
|
||||
# Prompt user for input
|
||||
read -p "Website: " url
|
||||
read -p "Login: " login
|
||||
read -s -p "Password: " password
|
||||
echo
|
||||
|
||||
domain=$(echo "$url" | sed -E 's~https?://([^/]+).*~\1~')
|
||||
hash=$(lhash "$login")
|
||||
pass_path="web/${domain}/${hash}"
|
||||
|
||||
# Entry content
|
||||
entry="${password}
|
||||
url: ${url}
|
||||
login: ${login}
|
||||
"
|
||||
|
||||
echo "$entry" | pass insert -m "$pass_path"
|
||||
|
||||
# url
|
||||
# login
|
||||
# tags
|
||||
# note
|
98
bin/cht
Executable file
98
bin/cht
Executable file
|
@ -0,0 +1,98 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import path from "path"
|
||||
import fs from "fs"
|
||||
|
||||
// DAT_ROOT should exists in ~/.zshrc-local
|
||||
const indexPath = path.join(process.env["NOTES_DIR"], "")
|
||||
const processFile = path.join(process.cwd(), process.argv[2])
|
||||
|
||||
|
||||
const data = fs.readFileSync(processFile, 'utf8')
|
||||
const jsonData = JSON.parse(data)
|
||||
|
||||
function wantSave(str) {
|
||||
return typeof str == "string" && str.split("\n").length > 10
|
||||
}
|
||||
|
||||
function saveToFileSync(content, file) {
|
||||
const dir = path.dirname(file);
|
||||
try {
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true })
|
||||
}
|
||||
|
||||
fs.writeFileSync(file, content, 'utf8')
|
||||
} catch (err) {
|
||||
console.error('Error saving file:', err)
|
||||
}
|
||||
}
|
||||
|
||||
const toSave = jsonData.flatMap(o => {
|
||||
const date = new Date(o.create_time * 1000)
|
||||
|
||||
// const formattedDate = date.toLocaleDateString('en-GB', {
|
||||
// day: '2-digit',
|
||||
// month: '2-digit',
|
||||
// year: '2-digit',
|
||||
// })
|
||||
// return formattedDate
|
||||
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const year = String(date.getFullYear()).slice(-2)
|
||||
|
||||
let baseNotePath = path.join(indexPath, "gpt", `${day}-${month}-${year}`, `${o.title}`)
|
||||
|
||||
let conversations = []
|
||||
for (const [key, value] of Object.entries(o.mapping)) {
|
||||
//console.log(key, value)
|
||||
|
||||
conversations.push({
|
||||
path: path.join(baseNotePath, `${key}.json`),
|
||||
content: JSON.stringify(value, null, 2)
|
||||
})
|
||||
|
||||
let parts = value?.message?.content.parts
|
||||
if (Array.isArray(parts)) {
|
||||
|
||||
if (parts.length == 0) {
|
||||
// skip
|
||||
} else if (parts.length == 1) {
|
||||
let fileName = path.join(baseNotePath, `${key}.md`)
|
||||
let md = parts[0]
|
||||
|
||||
if (wantSave(md)) {
|
||||
conversations.push({
|
||||
path: fileName,
|
||||
content: md
|
||||
})
|
||||
}
|
||||
} else {
|
||||
|
||||
for (const [key, value] of parts.entries()) {
|
||||
let fileName = path.join(baseNotePath, `${key}-${key+1}.md`)
|
||||
let md = parts[key]
|
||||
|
||||
if (wantSave(md)) {
|
||||
conversations.push({
|
||||
path: fileName,
|
||||
content: md
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//process.exit(-1)
|
||||
|
||||
}
|
||||
|
||||
return conversations
|
||||
})
|
||||
|
||||
|
||||
for(const f of toSave) {
|
||||
//for(const f of toSave.slice(0,5)) {
|
||||
saveToFileSync(f.content,f.path)
|
||||
}
|
16
bin/index
Executable file
16
bin/index
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
# find $NOTES_DIR/gpt -type d -path "$NOTES_DIR/gpt/[0-9][0-9]-[0-9][0-9]-[0-9][0-9]/*" | while read -r path; do
|
||||
# echo $(basename "$path")
|
||||
# done | sort -u | fzf
|
||||
|
||||
SEARCH_DIR="$NOTES_DIR/gpt"
|
||||
DELIMITER="|"
|
||||
|
||||
selected=$(find "$SEARCH_DIR" -type d -path "$SEARCH_DIR/[0-9][0-9]-[0-9][0-9]-[0-9][0-9]/*" | while read -r path; do
|
||||
topic=$(basename "$path")
|
||||
echo -e "$topic\t$path"
|
||||
done | fzf --delimiter='\t' --with-nth=1)
|
||||
|
||||
selected_path=$(echo "$selected" | cut -f2)
|
||||
echo "Path: $selected_path"
|
|
@ -6,4 +6,6 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
|
|||
elif [[ "$ARCH" == "x86_64" ]]; then
|
||||
eval "$(/usr/local/bin/brew shellenv)"
|
||||
fi
|
||||
|
||||
export PATH="$(brew --prefix ruby)/bin:$PATH"
|
||||
fi
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
export PATH="$DAT_ROOT/bin:$HOME/.local/bin:$PATH"
|
||||
|
||||
export GEM_HOME="$HOME/.gems"
|
||||
export GEM_PATH=$HOME/.gems
|
||||
|
||||
export RUBYLIB="$DAT_ROOT/lib"
|
||||
|
||||
export PASSWORD_STORE_DIR=$HOME/.local/lib/secure-vault/passwords
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue