Skip to content

Instantly share code, notes, and snippets.

@Mara-Li
Last active April 6, 2022 07:53
Show Gist options
  • Save Mara-Li/518c53626197c8be36a42acef3f49d87 to your computer and use it in GitHub Desktop.
Save Mara-Li/518c53626197c8be36a42acef3f49d87 to your computer and use it in GitHub Desktop.
FastStart Script for Obsidian (improved by python)
"""
Edit the path :
- `short` : The path to FastStart-Plugins-ShortDelay
- `long` : The path to FastStart-Plugins-LongDelay
- `plugin` : The absolute path to generated list by `FastStart-GenerateListOfInstalledPlugins`
Usage to class the list :
- [x] : will mark the plugin as "short"
- [any] : will mark the plugin as "long"
- Remove from the list / uncheck to keep at the actual state (disabled for ever, keep at start...)
"""
from pathlib import Path
import re
try:
from rich import print
except ImportError:
pass
short="G:\Mon Drive\Seed\Ressource\Superlinks\FastStart-Plugins-ShortDelay.md"
long="G:\Mon Drive\Seed\Ressource\Superlinks\FastStart-Plugins-LongDelay.md"
plugins="G:\Mon Drive\Seed\Ressource\Superlinks\plugins_list.md"
def class_plugin(plugins_file, short_file, long_file):
"""
Class the list of plugins
:param plugins_file: str
File path to the list of plugins
:param short_file: str
File path to the list of short delay plugins
:param long_file: str
File path to the list of long delay plugins
"""
with open(Path(plugins_file), 'r') as f:
plugins = f.readlines()
if '- [ ] templater-obsidian' in plugins:
plugins.remove('- [ ] templater-obsidian')
long = []
short = []
for i in plugins:
if i.startswith('- [x] '):
short.append(i.replace('- [x] ', ''))
elif not i.startswith('- [ ] '):
long.append(re.sub('- \[.*\] ', '', i))
short = "".join(sorted(short))
long = "".join(sorted(long))
with open(Path(short_file), 'w') as f:
f.write(short)
with open(Path(long_file), 'w') as f:
f.write(long)
try:
from rich import print
print('🎉 Successfully classed the list of plugins !\n\n⏱️ [b u]Short delay[/]:\n' + short + '\n\n⌚ [b u]Long delay[/]:\n' + long)
except ImportError:
print('🎉 Successfully classed the list of plugins !\n\n⏱️ Short delay :\n' + short + '\n\n⌚ Long delay: \n' + long)
class_plugin(plugins, short, long)
<%*
let plugins="- [ ] " + Object.values(app.plugins.manifests).map(p=>p.id).sort((a,b)=>a.localeCompare(b)).join('\n- [ ] ');
plugins = plugins.split('\n');
let long_delay = tp.file.find_tfile("FastStart-Plugins-LongDelay");
long_delay = await app.vault.read(long_delay)
long_delay=long_delay.split('\n');
let short_delay=tp.file.find_tfile("FastStart-Plugins-ShortDelay");
short_delay = await app.vault.read(short_delay)
short_delay=short_delay.split('\n');
for (var i =0;i<plugins.length;i++) {
const to_check = plugins[i].replace('- [ ] ', '')
if (short_delay.includes(to_check)) {
plugins[i] = plugins[i].replace('- [ ]', '- [x]');
}
else if (long_delay.includes(to_check)) {
plugins[i] = plugins[i].replace('- [ ]', '- [>]');
}
}
plugins = plugins.join('\n')
tR += plugins
%>
<%*
let plugins = tp.file.find_tfile('FastStart-Plugins-List')
plugins = await app.vault.read(plugins)
plugins = plugins.split('\n')
let short_plugins = []
let long_plugins = []
for (var i = 0; i < plugins.length;i++) {
if (plugins[i] != '- [ ] templater-obsidian') {
if (plugins[i].startsWith('- [x] ')) {
short_plugins.push(plugins[i].replace('- [x] ', ''))
}
else if (!plugins[i].startsWith('- [ ] ')) {
long_plugins.push(plugins[i].replace(/- \[.*\] */, ''))
}
}
}
const file_title = tp.file.title;
if (file_title == 'FastStart-Plugins-ShortDelay') {
tR+=short_plugins.join('\n')
}
else if (file_title == 'FastStart-Plugins-LongDelay') {
tR += long_plugins.join('\n')
}
else {
new Notice("Wrong file ! Don't forget to use the script in Long or Short delay files!", 5)
}
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment