Bash: Add languages to Chromium - bash

Is it possibe to use Bash to add languages to Chromium? That is, do the equivalent of going to Settings - Advanced - Languages in the Chromium GUI, activate the languages you want, and then activate spell-checking for the same languages? Had a look at this, but there doesn't seem to be anything that fits the bill.

Figured it out. The best way seems to be to add a Python block to read and manipulate the Preferences-file using the JSON library. Before you do anything, you need to get your bearings in the Preferences-file. What are the relevant elements that you need to change?
If you go to Preferences in the Chromium GUI, you can see that there are two relevant settings:
1) Languages:
2) Dictionaries (for spell check):
These can be found in the Preferences-file by pretty-printing the file in the terminal (improving it with pygmentize) or saving a pretty-printed output to a file:
less Preferences | python -m json.tool | pygmentize -g
or
~/.config/chromium/Default$ less Preferences | python -m json.tool >> ~/Documents/output.txt
Searching through the file for language settings, you will find two relevant elements:
"intl": {
"accept_languages": "en-US,en,nb,fr-FR,gl,de,gr,pt-PT,es-ES,sv"
},
and
"spellcheck": {
"dictionaries": [
"en-US",
"nb",
"de",
"gr",
"pt-PT",
"es-ES",
"sv"
],
"dictionary": ""
}
Before you do anything else, it is wise to backup the Preferences-file... Next,you can alter the language settings by adding the following python-block to the bash script:
python - << EOF
import json
import os
data = json.load(open(os.path.expanduser("~/.config/chromium/Default/Preferences"), 'r'))
data['intl'] = {"accept_languages": "en-US,en,nb,fr-FR,gl,de,pt-PT,es-ES,sv"}
data['spellcheck'] = {"dictionaries":["en-US","nb","de","pt-PT","es-ES","sv"],"dictionary":""}
with open(os.path.expanduser('~/.config/chromium/Default/Preferences'), 'w') as outfile:
json.dump(data, outfile)
EOF
In this case, the script will remove Greek from the available languages and the spellchecker. Note that in order to add languages, you need to know the language code accepted by Chromium.
You can find more on reading and writing JSON here and here, and more on how to include Python scripts in bash scripts here.

Related

In R markdown in RStudio, how can I prevent the source code from running off a pdf page when bash language is used?

I'm writing a technical book using Bookdown and RStudio. My code chunks are mainly using bash. Everything works fine except when I export the book to pdf, then the source code is partially out of the "box" and even the page if this is long enough. I have read a lot of solutions when r language is used, but none of these solutions works when bash language is used.
Here is my code at the beginning of the .Rmd file:
```{r, global_options, include=FALSE}
knitr::opts_chunk$set(message=FALSE, eval=FALSE,
tidy.opts=list(width.cutoff=60), tidy=TRUE)
```
And then when I write the code chunk:
```{bash}
mongodump --uri="mongodb+srv://cluster0.rh6qzzz.mongodb.net/" --db sample_mflix --username my_username
```
The outputs were produced as shown below (see the end of line):
I would like to avoid this, but I have not found the solution.

VSC temporarily turn off yaml lintin

Trying to find a way to turn off the red lines temporarily for that file only.
maybe try to disable the yaml.schemaStore ?
go in in settings.json and add :
"yaml.schemaStore.enable": false
Since this is not valid YAML at all, but you want to edit this as YAML,
you should make it into valid YAML. If you turn of the errors,
instead you probably would not have all of the advantage of the YAML
editing mode.
If saltstate allows you to change the block_start_string and
variable_start_string jinja2 uses you can change {% into #% (or
###% if #% and ###% naturally occur in your source), and also
change {{ into <{ (or <<{, you get the idea). If you would call
jinja2 directly you would then then pass to the FireSystemLoader:
block_start_string='<{' and variable_start_string='#%' If the
above is possible, then you have to change your input file only once,
do that with an editor.
If you cannot control saltstate to do the sane thing, your still not
stuck but you have to do a bit more using Python,
ruamel.yaml and some
support packages (disclaimer: I am the author of those packages).
Install with:
pip install ruamel.yaml[jinja2] ruamel.std.pathlib
Then before editing run the program:
from ruamel.yaml import YAML
from ruamel.std.pathlib import Path
yamlj2 = YAML(typ='jinja2')
yamlrt = YAML()
yaml_flow_style = YAML()
yaml_flow_style.default_flow_style = True
in_file = Path('init.sls')
backup_file = Path('init.sls.org')
in_file.copy(backup_file)
data = yamlj2.load(in_file)
with in_file.open('w') as fp:
# write the header with info needed for revers
fp.write('# ruamel.yaml.jinja2: ') # no EOL
yaml_flow_style.dump(yamlj2._plug_in_jinja2, fp)
yamlrt.dump(data, fp)
which changes the offending jinja2 sequences and add a one-line header comment with the actual patterns used to the file. You should then be able
to edit the init.sls file without getting all those errors.
Before calling saltstate, do run the following:
from ruamel.yaml import YAML
from ruamel.std.pathlib import Path
in_file = Path('init.sls')
yamlj2 = YAML(typ='jinja2')
yamlrt = YAML()
yamlnort = YAML(typ='safe')
with in_file.open() as fp:
yamlj2._plug_in_jinja2 = yamlnort.load(fp.readline().split(':', 1)[1])
data = yamlrt.load(fp)
yamlj2.dump(data, in_file)
If you have multiple of these files, you probably want to take your
filename from sys.argv[1]. You might actually call the salstate program from this second Python program (i.e. decode and run).

How to resemble the PDF-output of AsciidocFX using a Gradle build-script?

I have the following Asciidoc-document:
= Test
:doctype: article
:notitle:
:!toc:
AsciidocFX shows links in PDFs as footnotes http://stackoverflow.com[SO].
.Asciidoc in PDF does not work in Asciidoctor, but works in AsciidocFX.
[cols="2,5a"]
|===
|Line with Asciidoc code
|here comes a list:
* item 1
* item 2
* item 3
http://stackoverflow.com[Get Answers]!
|Line
|with a footnotefootnote:[footnotes do work in AsciidocFX's PDF output (but not in the preview).]
|===
When generating a PDF using asciidoctor, the output is as follows:
The problems are:
footnotes are shown inline (see: https://github.com/asciidoctor/asciidoctor-pdf/issues/73)
Asciidoc-content in tables cells is not interpreted: https://github.com/asciidoctor/asciidoctor-pdf/issues/6
Link targets are not shown as Footnotes (this would be nice to have)
Using https://github.com/asciidocfx/AsciidocFX shows everything correctly:
Now, I'd like to have the same output that AsciidocFX produces, but still like to use my Gradle build-script.
From https://github.com/asciidoctor/asciidoctor-pdf/issues/73#issuecomment-224327058 I learned, that AsciidoctorFX uses https://github.com/asciidoctor/asciidoctor-fopub[asciidoctor-fopub] under the hood. But how can I this pipeline in my build.gradle. Do I have to generate epub in a first task and use the output in another task? Or is there a direkt way?
Sorry that I am a tad late (almost 7 years!!) to answer your question, but perhaps it will help others.
Perhaps you need to upgrade. When I run your .adoc verbatim, the foootnotes come out perfectly. In fact the output is exactly as you posted correct version of output. Here is the syntax that I use:
asciidoctor-pdf -a pdf-themesdir=/path/to/themes -a pdf-theme=your-pdf-theme-file.yml -a pdf-fontsdir=/path/to/your/fonts/directory/ your_test_file.adoc
I put this syntax in a bash script with the adoc file as an argument.
I am using:
linux Pop!_OS 22.04 LTS (close derivative of ubuntu)
ruby 3.1.2p20
asciidoctor-pdf-2.3.0b
Ironically, I am amazed with is your AsciidoctorFX output. AsciidoctorFX pdf output looks horrible for me and there is no simple way of changing the output style, like editing the asciidoctor-pdf yaml.
Cheers, Joe

debugging littler/Rscripts

How do I debug Rscripts that are run from the command line?
I am currently using the getopt package to pass command line options, nut when there's a bug, it is hard for me to:
see what exactly went wrong;
debug interactively in R (since the script expects command line options.)
Does anyone have example code and willing to share?
You could pass your command line arguments into an interactive shell with --args and then source('') the script.
$ R --args -v
R version 2.8.1 (2008-12-22)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> require(getopt)
Loading required package: getopt
> opt = getopt(c(
+ 'verbose', 'v', 2, "integer"
+ ));
> opt
$verbose
[1] 1
> source('my_script.R')
You could now use the old browser() function to debug.
I either use old-school print statements, or interactive analysis. For that, I first save state using save(), and then load that into an interactive session (for which I use Emacs/ESS). That allows for interactive work using the script code on a line-by-line basis.
But I often write/test/debug the code in interactive mode first before I deploy in a littler script.
Another option is to work with the options(error) functionality. Here's a simple example:
options(error = quote({dump.frames(to.file=TRUE); q()}))
You can create as elaborate a script as you want on an error condition, so you should just decide what information you need for debugging.
Otherwise, if there are specific areas you're concerned about (e.g. connecting to a database), then wrap them in a tryCatch() function.

How to build a top-like UI in Ruby

I want to build an application with a text based UI that is similar to the Linux command 'top', in Ruby. What toolkits and/or techniques can I use to build the UI? In particular I want an area of the console window that is constantly updating, and the ability to press keys to manipulate the display.
For a terminal interface, see http://ncurses-ruby.berlios.de/
Ncurses is great for console apps and you can find bindings for it for lots of languages (or just use shell scripting). There's even a cursed gtk (http://zemljanka.sourceforge.net/cursed/) though I think work on it stopped quite awhile back.
You didn't mention your platform, but for OS/X there's a great little app called Geektool (http://projects.tynsoe.org/en/geektool/) which allows you to put script output on your desktop. I use a small ruby script to generate my top processes list:
puts %x{uptime}
IO.popen("ps aruxl") { |readme|
pslist = readme.to_a
pslist.shift # remove header line
pslist.each_with_index { |i,index|
ps = i.split
psh = { user: ps[0], pid: ps[1], pcpu: ps[2], pmem: ps[3],
vsz: ps[4], rss: ps[5], tty: ps[6], stat: ps[7],
time: ps[8], uid: ps[9], ppid: ps[10], cpu: ps[11], pri: ps[12],
nice: ps[13], wchan: ps[14], cmd: ps[16..ps.size].join(" ") }
printf("%-6s %-6s %-6s %s", "PID:", "%CPU:", "%Mem", "Command\n") if index == 0
printf("%-6d %-6.1f %-6.1f %s\n",
psh[:pid].to_i, psh[:pcpu].to_f, psh[:pmem].to_f, psh[:cmd]) if index < 10
}
}
(This could probably be better, but it was the first ruby script I ever wrote and since it works I've never revisited it to improve it - and it doesn't take input. Anyway, it might help give you some ideas)
there's stfl but i don't know if the ruby bindings are maintained. ncurses is probably your best bet.

Resources