summaryrefslogtreecommitdiff
path: root/.config/nushell/wishlist.nu
diff options
context:
space:
mode:
authorWriterV2 <primary-v2@protonmail.com>2026-04-03 22:46:48 +0200
committerWriterV2 <primary-v2@protonmail.com>2026-04-03 22:46:48 +0200
commita1ec4771740d321df4480e8a7224fa10b59f0569 (patch)
tree5e97e8ced79b4fea057fab6e76f80849c053e401 /.config/nushell/wishlist.nu
Update repo with git init directly in home dir
Diffstat (limited to '.config/nushell/wishlist.nu')
-rw-r--r--.config/nushell/wishlist.nu183
1 files changed, 183 insertions, 0 deletions
diff --git a/.config/nushell/wishlist.nu b/.config/nushell/wishlist.nu
new file mode 100644
index 0000000..10cc0f5
--- /dev/null
+++ b/.config/nushell/wishlist.nu
@@ -0,0 +1,183 @@
+export def add [
+ name: string, # name of the item
+ --comment: string, # comment for the item
+ --sources: list<string>, # a source to acquire the item, typically a URL
+ --importance: int # a number to indicate the importance, choose the scaling yourself, default: 0
+] {
+ let item_id = random uuid
+ {
+ id: $item_id,
+ name: $name,
+ comment: ($comment | default ''),
+ acquired: false,
+ importance: ($importance | default 0)
+ } | into sqlite $env.WISHLIST_DB_PATH
+
+ print $"Added ($name) successfully to the wishlist."
+
+ if $sources != null and ($sources | length) > 0 {
+ $sources | each { |source|
+ let link_id = random uuid
+ {
+ id: (random uuid),
+ item_id: $item_id,
+ content: $source
+ } | into sqlite $env.WISHLIST_DB_PATH -t sources
+ }
+ print $"Added sources for ($name) successfully."
+ }
+ show --id $item_id
+}
+
+export def show [
+ --id: string, # id of the item, identify using `wishlist show --explore`
+ --explore # show in nushell explorer
+] {
+ if not ($env.WISHLIST_DB_PATH | path exists) {
+ print "Wishlist is empty. If it shouldn't be empty, check the WISHLIST_DB_PATH environment variable."
+ return
+ }
+ mut wishlist = open $env.WISHLIST_DB_PATH | get main
+
+ if $id != null {
+ $wishlist = $wishlist | where id == $id
+ }
+
+ if ($explore) {
+ return ($wishlist | explore -p)
+ }
+
+ return $wishlist
+}
+
+export def set-comment [
+ id: string, # id of the item, identify using `wishlist show --explore`
+ comment: string
+] {
+ if not ($env.WISHLIST_DB_PATH | path exists) {
+ print "Wishlist database was not found. If this shouldn't happen, check the WISHLIST_DB_PATH environment variable."
+ return
+ }
+
+ open $env.WISHLIST_DB_PATH | query db "UPDATE main SET comment = ? WHERE id = ?" -p [$comment, $id]
+ print $"Updated comment for item with id ($id) successfully."
+ show --id $id
+}
+
+export def set-importance [
+ id: string, # id of the item, identify using `wishlist show --explore`
+ importance: int
+] {
+ if not ($env.WISHLIST_DB_PATH | path exists) {
+ print "Wishlist database was not found. If this shouldn't happen, check the WISHLIST_DB_PATH environment variable."
+ return
+ }
+
+ open $env.WISHLIST_DB_PATH | query db "UPDATE main SET importance = ? WHERE id = ?" -p [$importance, $id]
+ print $"Updated importance for item with id ($id) successfully."
+ show --id $id
+}
+
+export def check [
+ id: string, # id of the item, identify using `wishlist show --explore`
+] {
+ if not ($env.WISHLIST_DB_PATH | path exists) {
+ print "Wishlist database was not found. If this shouldn't happen, check the WISHLIST_DB_PATH environment variable."
+ return
+ }
+
+ open $env.WISHLIST_DB_PATH | query db "UPDATE main SET acquired = true WHERE id = ?" -p [$id]
+ print $"Checked off item with id ($id) successfully."
+ show --id $id
+
+}
+
+export def remove [
+ id: string, # id of the item, identify using `wishlist show --explore`
+] {
+ if not ($env.WISHLIST_DB_PATH | path exists) {
+ print "Wishlist database was not found. If this shouldn't happen, check the WISHLIST_DB_PATH environment variable."
+ return
+ }
+
+ open $env.WISHLIST_DB_PATH | query db "DELETE FROM main WHERE id = ?" -p [$id]
+ print $"Removed item with id ($id) successfully."
+ show
+}
+
+# Get the highest value of importance in the wishlist
+export def highest-importance [] {
+ show | get importance | reduce { |it, acc| if ($it > $acc) { $it } else { $acc }}
+}
+
+# Get the lowest value of importance in the wishlist
+export def lowest-importance [] {
+ show | get importance | reduce { |it, acc| if ($it < $acc) { $it } else { $acc }}
+}
+
+export def "sources show" [
+ --id: string, # id of the source, identify using `wishlist sources show --explore`
+ --item-id: string, # id of the item, identify using `wishlist show --explore`
+ --explore # show in nushell explorer
+] {
+ if not ($env.WISHLIST_DB_PATH | path exists) {
+ print "Wishlist database was not found. If this shouldn't happen, check the WISHLIST_DB_PATH environment variable."
+ return
+ }
+
+ mut sources = open $env.WISHLIST_DB_PATH | get sources
+
+ if $id != null {
+ $sources = $sources | where id == $id
+ } else if $item_id != null {
+ $sources = $sources | where item_id == $item_id
+ }
+
+ if ($explore) {
+ return ($sources | explore -p)
+ }
+
+ return $sources
+}
+
+export def "sources add" [
+ content: string # content of the source to acquire the item, typically a URL
+ item_id: string, # id of the item, identify using `wishlist show --explore`
+] {
+ let source_id = random uuid
+ {
+ id: $source_id,
+ item_id: $item_id,
+ content: $content,
+ } | into sqlite $env.WISHLIST_DB_PATH -t sources
+ print $"Added new source to item with id ($item_id) successfully."
+ sources show --id $source_id
+}
+
+export def "sources update" [
+ id: string # id of the source, identify using `wishlist sources show --explore`
+ content: string # new content for the given source
+] {
+ if not ($env.WISHLIST_DB_PATH | path exists) {
+ print "Wishlist database was not found. If this shouldn't happen, check the WISHLIST_DB_PATH environment variable."
+ return
+ }
+
+ open $env.WISHLIST_DB_PATH | query db "UPDATE sources SET content = ? WHERE id = ?" -p [$content, $id]
+ print $"Updated source with id ($id) successfully."
+ sources show --id $id
+}
+
+export def "sources remove" [
+ id: string, # id of the source, identify using `wishlist sources show --explore`
+] {
+ if not ($env.WISHLIST_DB_PATH | path exists) {
+ print "Wishlist database was not found. If this shouldn't happen, check the WISHLIST_DB_PATH environment variable."
+ return
+ }
+
+ open $env.WISHLIST_DB_PATH | query db "DELETE FROM sources WHERE id = ?" -p [$id]
+ print $"Removed source with id ($id) successfully."
+ sources show
+}
+