You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-06 09:19:22 +02:00
Updated translation
This commit is contained in:
@@ -17,8 +17,6 @@ import { fileExtension } from 'lib/path-utils.js';
|
||||
import { _, setLocale, defaultLocale, closestSupportedLocale } from 'lib/locale.js';
|
||||
import os from 'os';
|
||||
import fs from 'fs-extra';
|
||||
import yargParser from 'yargs-parser';
|
||||
import { handleAutocompletion, installAutocompletionFile } from './autocompletion.js';
|
||||
import { cliUtils } from './cli-utils.js';
|
||||
const EventEmitter = require('events');
|
||||
|
||||
@@ -28,7 +26,6 @@ class Application {
|
||||
this.showPromptString_ = true;
|
||||
this.logger_ = new Logger();
|
||||
this.dbLogger_ = new Logger();
|
||||
this.autocompletion_ = { active: false };
|
||||
this.commands_ = {};
|
||||
this.commandMetadata_ = null;
|
||||
this.activeCommand_ = null;
|
||||
@@ -202,37 +199,6 @@ class Application {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg == '--autocompletion') {
|
||||
this.autocompletion_.active = true;
|
||||
argv.splice(0, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg == '--ac-install') {
|
||||
this.autocompletion_.install = true;
|
||||
argv.splice(0, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg == '--ac-current') {
|
||||
if (!nextArg) throw new Error(_('Usage: %s', '--ac-current <num>'));
|
||||
this.autocompletion_.current = nextArg;
|
||||
argv.splice(0, 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg == '--ac-line') {
|
||||
if (!nextArg) throw new Error(_('Usage: %s', '--ac-line <line>'));
|
||||
let line = nextArg.replace(/\|__QUOTE__\|/g, '"');
|
||||
line = line.replace(/\|__SPACE__\|/g, ' ');
|
||||
line = line.replace(/\|__OPEN_RB__\|/g, '(');
|
||||
line = line.replace(/\|__OPEN_CB__\|/g, ')');
|
||||
line = line.split('|__SEP__|');
|
||||
this.autocompletion_.line = line;
|
||||
argv.splice(0, 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg.length && arg[0] == '-') {
|
||||
throw new Error(_('Unknown flag: %s', arg));
|
||||
} else {
|
||||
@@ -611,10 +577,6 @@ class Application {
|
||||
return this.stdout(object);
|
||||
});
|
||||
|
||||
// this.store_ = createStore(reducer, applyMiddleware(this.generalMiddleware()));
|
||||
// BaseModel.dispatch = this.store().dispatch;
|
||||
// FoldersScreenUtils.dispatch = this.store().dispatch;
|
||||
|
||||
await Setting.load();
|
||||
|
||||
if (Setting.value('firstStart')) {
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
import { app } from './app.js';
|
||||
import { Note } from 'lib/models/note.js';
|
||||
import { Folder } from 'lib/models/folder.js';
|
||||
import { Tag } from 'lib/models/tag.js';
|
||||
import { cliUtils } from './cli-utils.js';
|
||||
import { _ } from 'lib/locale.js';
|
||||
import fs from 'fs-extra';
|
||||
import os from 'os';
|
||||
import yargParser from 'yargs-parser';
|
||||
|
||||
function autocompletionFileContent(appName, alias) {
|
||||
let content = fs.readFileSync(__dirname + '/autocompletion_template.txt', 'utf8');
|
||||
content = content.replace(/\|__APPNAME__\|/g, appName);
|
||||
|
||||
if (!alias) alias = 'joplin_alias_support_is_disabled';
|
||||
content = content.replace(/\|__APPALIAS__\|/g, alias);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
function autocompletionScriptPath(profileDir) {
|
||||
return profileDir + '/autocompletion.sh';
|
||||
}
|
||||
|
||||
async function installAutocompletionFile(appName, profileDir) {
|
||||
if (process.env.SHELL.indexOf('bash') < 0) {
|
||||
let error = new Error(_('Only Bash is currently supported for autocompletion.'));
|
||||
error.code = 'shellNotSupported';
|
||||
throw error;
|
||||
}
|
||||
|
||||
const alias = await cliUtils.promptInput(_('Autocompletion can be made to work with an alias too (such as a one-letter command like "j").\nIf you would like to enable this, please type the alias now (leave it empty for no alias):'));
|
||||
|
||||
const content = autocompletionFileContent(appName, alias);
|
||||
const filePath = autocompletionScriptPath(profileDir);
|
||||
fs.writeFileSync(filePath, content);
|
||||
|
||||
console.info(_('Created autocompletion script "%s".', filePath));
|
||||
|
||||
const bashProfilePath = os.homedir() + '/.bashrc';
|
||||
|
||||
let bashrcContent = fs.readFileSync(bashProfilePath, 'utf8');
|
||||
|
||||
const lineToAdd = 'source ' + filePath;
|
||||
|
||||
if (bashrcContent.indexOf(lineToAdd) >= 0) {
|
||||
console.info(_('Autocompletion script is already present in "%s".', bashProfilePath));
|
||||
} else {
|
||||
bashrcContent += "\n" + lineToAdd + "\n";
|
||||
fs.writeFileSync(bashProfilePath, bashrcContent);
|
||||
console.info(_('Added autocompletion to "%s".', bashProfilePath));
|
||||
}
|
||||
|
||||
if (alias) {
|
||||
if (bashrcContent.indexOf('alias ' + alias + '=') >= 0) {
|
||||
console.info(_('Alias is already set in "%s".', bashProfilePath));
|
||||
} else {
|
||||
const l = 'alias ' + alias + '=' + appName;
|
||||
bashrcContent += "\n" + l + "\n";
|
||||
fs.writeFileSync(bashProfilePath, bashrcContent);
|
||||
console.info(_('Added alias to "%s".', bashProfilePath));
|
||||
}
|
||||
}
|
||||
|
||||
console.info(_("IMPORTANT: run the following command to initialise autocompletion in the current shell:\nsource '%s'", filePath));
|
||||
}
|
||||
|
||||
async function handleAutocompletion(autocompletion) {
|
||||
let args = autocompletion.line.slice();
|
||||
args.splice(0, 1);
|
||||
let current = autocompletion.current - 1;
|
||||
const currentWord = args[current] ? args[current] : '';
|
||||
|
||||
// Auto-complete the command name
|
||||
|
||||
if (current == 0) {
|
||||
const metadata = await app().commandMetadata();
|
||||
let commandNames = [];
|
||||
for (let n in metadata) {
|
||||
if (!metadata.hasOwnProperty(n)) continue;
|
||||
const md = metadata[n];
|
||||
if (md.hidden) continue;
|
||||
if (currentWord == n) return [n];
|
||||
if (n.indexOf(currentWord) === 0) commandNames.push(n);
|
||||
}
|
||||
return commandNames;
|
||||
}
|
||||
|
||||
const commandName = args[0];
|
||||
const metadata = await app().commandMetadata();
|
||||
const md = metadata[commandName];
|
||||
const options = md && md.options ? md.options : [];
|
||||
|
||||
// Auto-complete the command options
|
||||
|
||||
if (currentWord) {
|
||||
const includeLongs = currentWord.length == 1 ? currentWord.substr(0, 1) == '-' : currentWord.substr(0, 2) == '--';
|
||||
const includeShorts = currentWord.length <= 2 && currentWord.substr(0, 1) == '-' && currentWord.substr(0, 2) != '--';
|
||||
|
||||
if (includeLongs || includeShorts) {
|
||||
const output = [];
|
||||
for (let i = 0; i < options.length; i++) {
|
||||
const flags = cliUtils.parseFlags(options[i][0]);
|
||||
const long = flags.long ? '--' + flags.long : null;
|
||||
const short = flags.short ? '-' + flags.short : null;
|
||||
if (includeLongs && long && long.indexOf(currentWord) === 0) output.push(long);
|
||||
if (includeShorts && short && short.indexOf(currentWord) === 0) output.push(short);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-complete the command arguments
|
||||
|
||||
let argIndex = -1;
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const w = args[i];
|
||||
if (i == 0 || w.indexOf('-') == 0) {
|
||||
continue;
|
||||
}
|
||||
argIndex++;
|
||||
}
|
||||
|
||||
if (argIndex < 0) return [];
|
||||
|
||||
let cmdUsage = yargParser(md.usage)['_'];
|
||||
cmdUsage.splice(0, 1);
|
||||
|
||||
if (cmdUsage.length <= argIndex) return [];
|
||||
|
||||
let argName = cmdUsage[argIndex];
|
||||
argName = cliUtils.parseCommandArg(argName).name;
|
||||
|
||||
if (argName == 'note' || argName == 'note-pattern') {
|
||||
if (!app().currentFolder()) return [];
|
||||
const notes = await Note.previews(app().currentFolder().id, { titlePattern: currentWord + '*' });
|
||||
return notes.map((n) => n.title);
|
||||
}
|
||||
|
||||
if (argName == 'notebook') {
|
||||
const folders = await Folder.search({ titlePattern: currentWord + '*' });
|
||||
return folders.map((n) => n.title);
|
||||
}
|
||||
|
||||
if (argName == 'tag') {
|
||||
let tags = await Tag.search({ titlePattern: currentWord + '*' });
|
||||
return tags.map((n) => n.title);
|
||||
}
|
||||
|
||||
if (argName == 'tag-command') {
|
||||
return filterList(['add', 'remove', 'list'], currentWord);
|
||||
}
|
||||
|
||||
if (argName == 'todo-command') {
|
||||
return filterList(['toggle', 'clear'], currentWord);
|
||||
}
|
||||
|
||||
if (argName == 'command') {
|
||||
const commands = await app().commandNames();
|
||||
return this.filterList(commands, currentWord);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
function filterList(list, currentWord) {
|
||||
let output = [];
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
if (list[i].indexOf(currentWord) !== 0) continue;
|
||||
output.push(list[i]);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
export { handleAutocompletion, installAutocompletionFile, autocompletionScriptPath };
|
||||
@@ -1,44 +0,0 @@
|
||||
export IFS=$'\n'
|
||||
|
||||
_|__APPNAME__|_completion() {
|
||||
|
||||
# COMP_WORDS contains each word in the current command, the last one
|
||||
# being the one that needs to be completed. Convert this array
|
||||
# to an "escaped" line which can be passed to the joplin CLI
|
||||
# which will provide the possible autocompletion words.
|
||||
|
||||
ESCAPED_LINE=""
|
||||
for WORD in "${COMP_WORDS[@]}"
|
||||
do
|
||||
if [[ -n $ESCAPED_LINE ]]; then
|
||||
ESCAPED_LINE="$ESCAPED_LINE|__SEP__|"
|
||||
fi
|
||||
WORD="${WORD/\"/|__QUOTE__|}"
|
||||
WORD="${WORD/\\(/|__OPEN_RB__|}"
|
||||
WORD="${WORD/\\)/|__CLOSE_RB__|}"
|
||||
WORD="${WORD/\\ /|__SPACE__|}"
|
||||
ESCAPED_LINE="$ESCAPED_LINE$WORD"
|
||||
done
|
||||
|
||||
# Call joplin with the --autocompletion flag to retrieve the autocompletion
|
||||
# candidates (each on its own line), and put these into COMREPLY.
|
||||
|
||||
# echo "joplindev --autocompletion --ac-current "$COMP_CWORD" --ac-line "$ESCAPED_LINE"" > ~/test.txt
|
||||
|
||||
COMPREPLY=()
|
||||
while read -r line; do
|
||||
COMPREPLY+=("$line")
|
||||
done <<< "$(|__APPNAME__| --autocompletion --ac-current "$COMP_CWORD" --ac-line "$ESCAPED_LINE")"
|
||||
|
||||
# If there's only one element and it's empty, make COMREPLY
|
||||
# completely empty so that default completion takes over
|
||||
# (i.e. regular file completion)
|
||||
# https://stackoverflow.com/a/19062943/561309
|
||||
|
||||
if [[ -z ${COMPREPLY[0]} ]]; then
|
||||
COMPREPLY=()
|
||||
fi
|
||||
}
|
||||
|
||||
complete -o default -F _|__APPNAME__|_completion |__APPNAME__|
|
||||
complete -o default -F _|__APPNAME__|_completion |__APPALIAS__|
|
||||
@@ -73,9 +73,9 @@ class Command extends BaseCommand {
|
||||
this.stdout('');
|
||||
this.stdout(_('In any command, a note or notebook can be refered to by title or ID, or using the shortcuts `$n` or `$b` for, respectively, the currently selected note or notebook. `$c` can be used to refer to the currently selected item.'));
|
||||
this.stdout('');
|
||||
this.stdout(_('To move from one widget to another, press Tab or Shift+Tab.'));
|
||||
this.stdout(_('To move from one pane to another, press Tab or Shift+Tab.'));
|
||||
this.stdout(_('Use the arrows and page up/down to scroll the lists and text areas (including this console).'));
|
||||
this.stdout(_('To maximise/minimise the console, press "C".'));
|
||||
this.stdout(_('To maximise/minimise the console, press "TC".'));
|
||||
this.stdout(_('To enter command line mode, press ":"'));
|
||||
this.stdout(_('To exit command line mode, press ESCAPE'));
|
||||
this.stdout(_('For the complete list of available keyboard shortcuts, type `help shortcuts`'));
|
||||
|
||||
Reference in New Issue
Block a user