From 1f62bb41a7ff1a6f0e88dfa3c97e6724eab5d411 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Wed, 14 Jun 2017 08:06:40 +0200 Subject: [PATCH] Commit in a looong time --- bashrc | 20 +++++++- config/htop/htoprc | 4 +- config/i3/config | 2 +- config/i3status/config | 10 ++-- scripts/.gitignore | 1 + scripts/html2pdf | 52 +++++++++++++++++++ scripts/md2html | 113 +++++++++++++++++++++++++++++++++++++++++ scripts/package.json | 22 ++++++++ scripts/remcrlf | 5 ++ scripts/transfer | 20 ++++++++ vimrc | 2 +- 11 files changed, 241 insertions(+), 10 deletions(-) create mode 100755 scripts/html2pdf create mode 100755 scripts/md2html create mode 100644 scripts/package.json create mode 100755 scripts/remcrlf create mode 100755 scripts/transfer diff --git a/bashrc b/bashrc index caac99c..a673ee2 100644 --- a/bashrc +++ b/bashrc @@ -24,6 +24,9 @@ export JAVA_FONTS=/usr/share/fonts/TTF export ANDROID_HOME=/opt/android-sdk export GOPATH=$HOME/.go export XDG_CONFIG_HOME=$HOME/.config +export ARDUINO=/usr/share/arduino +export ARDUINO_DIR=$ARDUINO +export ARDMK_VENDOR=archlinux-arduino # ALIASES @@ -39,6 +42,12 @@ alias rm='rm -Iv --one-file-system' alias free='free -m' alias df='df -h' alias pacman='pacman --color auto' +alias dmesg='dmesg --ctime' + +# Frequent mistakes +alias systemclt=systemctl +alias docker='sudo docker' +alias docker-compose='sudo docker-compose' # Shortcuts for commonly used commands alias ll="ls -l $LS_OPTIONS" @@ -49,6 +58,10 @@ alias s='sudo -s -E' alias po='eval $(proxy off)' alias nw="sudo systemctl restart NetworkManager" alias mc="machines" +alias vpn="sudo systemctl start openvpn-client@$HOSTNAME" +alias vpno="sudo systemctl stop openvpn-client@$HOSTNAME" +alias vpns="sudo systemctl status openvpn-client@$HOSTNAME" +alias vpnr="sudo systemctl restart openvpn-client@$HOSTNAME" # Superseding commands with better ones if they are present if which vim &> /dev/null; then alias vi='vim' @@ -73,7 +86,7 @@ shopt -s extglob shopt -s histappend shopt -s hostcomplete -export HISTSIZE=10000 +export HISTSIZE=100000 export HISTFILESIZE=${HISTSIZE} export HISTCONTROL=ignoreboth @@ -111,3 +124,8 @@ fi [ -r /usr/share/doc/pkgfile/command-not-found.bash ] && . /usr/share/doc/pkgfile/command-not-found.bash # Arch [ -r /etc/profile.d/cnf.sh ] && . /etc/profile.d/cnf.sh # Arch (alternative, for Manjaro mostly) +# Node Version Manager +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion diff --git a/config/htop/htoprc b/config/htop/htoprc index 51bf9c4..ee794e5 100644 --- a/config/htop/htoprc +++ b/config/htop/htoprc @@ -1,14 +1,14 @@ # Beware! This file is rewritten by htop when settings are changed in the interface. # The parser is also very primitive, and not human-friendly. fields=0 48 17 18 38 39 40 2 46 47 49 1 -sort_key=47 +sort_key=46 sort_direction=1 hide_threads=0 hide_kernel_threads=0 hide_userland_threads=0 shadow_other_users=0 show_thread_names=0 -show_program_path=1 +show_program_path=0 highlight_base_name=0 highlight_megabytes=0 highlight_threads=1 diff --git a/config/i3/config b/config/i3/config index 98a525d..5da53bb 100644 --- a/config/i3/config +++ b/config/i3/config @@ -51,7 +51,7 @@ set $up_bar killall -USR1 i3status # Start Applications bindsym $mod+Return exec xterm bindsym $mod+p exec thunar -bindsym $mod+m exec qutebrowser +bindsym $mod+m exec qutebrowser --override-restore # Volume control #bindsym XF86AudioRaiseVolume exec amixer -q set Master 5+ unmute; exec $up_bar diff --git a/config/i3status/config b/config/i3status/config index 4e38eb4..5860ec6 100644 --- a/config/i3status/config +++ b/config/i3status/config @@ -36,7 +36,7 @@ ethernet eth0 { ethernet usb0 { # if you use %speed, i3status requires the cap_net_admin capability format_up = " %ip" - format_down = "" + format_down = "📱" } cpu_usage { @@ -56,11 +56,11 @@ battery 0 { path_exists VPN { # path exists when a VPN tunnel launched by nmcli/nm-applet is active path = "/proc/sys/net/ipv4/conf/tun0" - format = "" + format = "🔐" } tztime local { - format = "%d/%m/%Y %H:%M:%S" + format = "🕘 %d/%m/%Y %H:%M:%S" timezone = "Europe/Paris" } @@ -76,8 +76,8 @@ disk "/home" { format = " %avail / %total" } volume master { - format = " %volume" - format_muted = " %volume" + format = "🔈 %volume" + format_muted = "🔇 %volume" device = "default" mixer = "Master" mixer_idx = 0 diff --git a/scripts/.gitignore b/scripts/.gitignore index 28a5280..98b66d7 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -1 +1,2 @@ sct +node_modules diff --git a/scripts/html2pdf b/scripts/html2pdf new file mode 100755 index 0000000..8095bd4 --- /dev/null +++ b/scripts/html2pdf @@ -0,0 +1,52 @@ +#!/usr/bin/env node + +// Imports +var fs = require('fs'); +var pdf = require('html-pdf'); +var yargs = require('yargs'); + + +// Understanding +var argv = yargs + .usage("Usage: $0 -o out.pdf [options]") + .example('$0 -i doc.pdf -o doc.pdf', 'Convert doc.html to PDF using the default values') + .help('h') + .alias('h', 'help') + + .describe('i', 'Input file') + .alias('i', 'input') + .default('i', '/dev/stdin') + + .describe('o', 'Output file') + .alias('o', 'output') + + .describe('t', 'Title of file') + .alias('t', 'title') + .default('t', 'Sans titre') + + .demandOption(['o']) + .argv; + + +// Settings +options = { + "base": "file://" + process.cwd() + '/', + "format": "A4", + "orientation": "portrait", + "border": "2cm", + + "footer": { + "height": "10mm", + "contents": { + default: '
' + argv.title + '
{{page}}/{{pages}}
', + } + }, +} + +// Reading +htmlString = fs.readFileSync(argv.i, "utf8"); + +// Conversion +pdf.create(htmlString, options).toFile(argv.o, function(err, res) { + if (err) console.error(err); +}); diff --git a/scripts/md2html b/scripts/md2html new file mode 100755 index 0000000..d284ada --- /dev/null +++ b/scripts/md2html @@ -0,0 +1,113 @@ +#!/usr/bin/env node + +// Imports +var fs = require('fs'); +var marked = require('marked'); +var highlight = require('highlight.js'); +var katex = require('katex'); +var yargs = require('yargs'); +var extend = require('util')._extend; + + +// Constants +var template = ' %TITLE%
%BODY%
' + + +// Understanding +var argv = yargs + .usage("Usage: $0 [options]") + .example('$0 -i doc.md -o doc.html', 'Convert doc.md to HTML using the default template') + .help('h') + .alias('h', 'help') + + .describe('i', 'Input file') + .alias('i', 'input') + .default('i', '/dev/stdin') + + .describe('o', 'Output file') + .alias('o', 'output') + .default('o', '/dev/stdout') + + .describe('t', 'Template file (%BODY% is replaced by the text)') + .alias('t', 'template') + + .argv; + +if (argv.t) { + template = fs.readFileSync(argv.t, "utf8"); +} + + +// Settings + +var extraLangages = { + avrpseudo: function (hljs) { + lang = extend({}, highlight.getLanguage('avrasm')); + lang.keywords.keyword += ' Si Alors Sinon FinSi TantQue FinTantQue Pour FinPour allant de à ←'; + lang.keywords.keyword += ' Lire Sortir sur Appeler Retourner'; + lang.keywords.keyword += ' DecalerDroite DecalerGauche'; + lang.keywords.keyword += ' Incrementer Decrementer'; + lang.keywords.built_in += ' vrai faux'; + lang.contains.push({ + className: 'meta', + begin: /Configurer.+/, + end: /\n/, + }); + return lang; + }, + avrasmplus: function (hljs) { + lang = extend({}, highlight.getLanguage('avrasm')); + lang.keywords.keyword += ' si saut alors et ou if then goto && || <-'; + lang.contains.push({ + className: 'meta', + begin: /@\w+/, + }); + return lang; + }, +}; + +for (lang in extraLangages) { + // This must be done before any call to highlight.highlight :/ + highlight.registerLanguage(lang, extraLangages[lang]); +} + +var renderer = new marked.Renderer(); +marked.setOptions({ + highlight: function (code, lang) { + if (highlight.getLanguage(lang)) { + return highlight.highlight(lang, code).value; + } else { + // if (extraLangages[lang]) { + // highlight.registerLanguage(lang, extraLangages[lang]); + // return highlight.highlight(lang, code).value; + // } else { + // } + console.warn("Unknown language: " + lang); + return highlight.highlightAuto(code).value; + } + } +}); + + +// Processing +markdownString = fs.readFileSync(argv.i, "utf8"); + +// TeX +markdownString = markdownString.replace(/\\\$/g, '$') +markdownString = markdownString.replace(/\$\$([\s\S]+)\$\$/gm, function(glob, formula) { + return katex.renderToString(formula, {displayMode: true}); +}); +markdownString = markdownString.replace(/\$([^$]+)\$/g, function(glob, formula) { + return katex.renderToString(formula, {displayMode: false}); +}); + +// Conversion +htmlString = marked(markdownString, {renderer: renderer}); +fullHtmlString = template.replace('%BODY%', htmlString); + +// Saving +if (argv.o == '/dev/stdout') { + console.log(fullHtmlString); +} else { + fs.writeFileSync(argv.o, fullHtmlString); +} diff --git a/scripts/package.json b/scripts/package.json new file mode 100644 index 0000000..2d615ab --- /dev/null +++ b/scripts/package.json @@ -0,0 +1,22 @@ +{ + "name": "geoffreyfrogeye-dotfiles-scripts", + "version": "1.0.0", + "description": "Stores dependencies used for GeoffreyFrogeye's dotfiles scripts.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://git.frogeye.fr/geoffrey/dotfiles" + }, + "author": "GeoffreyFrogeye", + "license": "GPL-3.0", + "dependencies": { + "highlight.js": "^9.11.0", + "html-pdf": "^2.1.0", + "katex": "^0.7.1", + "marked": "^0.3.6", + "yargs": "^8.0.1" + } +} diff --git a/scripts/remcrlf b/scripts/remcrlf new file mode 100755 index 0000000..ca0f98c --- /dev/null +++ b/scripts/remcrlf @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +# Removes CRLF (^M or \r) from a file + +sed -e "s/^M//" $1 -i diff --git a/scripts/transfer b/scripts/transfer new file mode 100755 index 0000000..a937228 --- /dev/null +++ b/scripts/transfer @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +if [ $# -eq 0 ] +then + echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md" + return 1 +fi + +tmpfile=$( mktemp -t transferXXX ) + +if tty -s +then + basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g') + curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile +else + curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile +fi + +cat $tmpfile +rm -f $tmpfile diff --git a/vimrc b/vimrc index c2d7a89..9f319f7 100644 --- a/vimrc +++ b/vimrc @@ -44,7 +44,7 @@ nmap :UndotreeToggle:UndotreeFocus """ CTRLP """ let g:ctrlp_custom_ignore = { - \ 'dir': '\v([\/]\.(git|hg|svn)|node_modules|bower_components|__pycache__|vendor)$', + \ 'dir': '\v([\/]\.(git|hg|svn)|node_modules|bower_components|__pycache__|vendor|output)$', \ 'file': '\v\.(exe|so|dll)$', \ 'link': 'SOME_BAD_SYMBOLIC_LINKS', \ }