Commit e0ae921f authored by Glen Mével's avatar Glen Mével

first commit

parents
#!/bin/sh
# Save the bell settings and activate it if needed.
settings=$(xset -q |grep bell |grep -o '[0-9]*')
xset b ${settings/#0/50}
# Ring the bell.
echo -ne '\a'
# Restore the bell settings.
xset b $settings
#!/bin/sh
# Colorize diff’s output (unified style).
#
# Note that ‘diff’ already supports colors but that, for some reason, it doesn’t
# colorize all lines (only the first line of each difference).
color="auto"
args=()
for arg in "$@" ; do
if [ "$arg" == "--color=never" ] ; then
color="never"
elif [ "$arg" == "--color=always" ] ; then
color="always"
elif [ "$arg" == "--color=auto" ] ; then
color="auto"
else
args+=( "$arg" )
fi
done
if [ "$color" == "always" -o '(' "$color" == "auto" -a -t 1 ')' ] ; then
/usr/bin/diff -u --color=never "${args[@]}" \
|sed 's/^Only in/\x1B[43;1;30mOnly in/;
s/^Files/\x1B[45;1mFiles/;
s/^diff/\x1B[1;30mdiff/;
s/^--- /\x1B[1;31m--- /;
s/^+++ /\x1B[1;32m+++ /;
s/^@@/\x1b[34m@@/;
s/^-/-\x1b[41m/;
s/^+/+\x1b[42m/;
s/^ / \x1B[30m/;
s/$/\x1b[0m/'
else
/usr/bin/diff -u --color=never "${args[@]}"
fi
#!/usr/bin/ocaml
(*
* Reads an UTF-8 text and writes it on standard output. Invalid codes are
* regarded as CP1252-encoded characters and are converted to UTF-8.
*)
let substitute = "�"
let buf = object (self)
val buf = Bytes.make 4 '\x00'
val mutable first = 0
val mutable cur = 0
val mutable last = 0
method input () =
Char.code @@
if cur < last then
let b = Bytes.get buf (cur mod 4) in
cur <- cur + 1 ;
b
else
let b = input_char stdin in
Bytes.set buf (cur mod 4) b ;
cur <- cur + 1 ;
last <- cur ;
assert (first <= last && last <= first + 4) ;
b
method rewind () =
cur <- first
method discard () =
first <- cur
method consume ?(keep=0) f =
self#rewind () ;
while cur < last - keep do
f (self#input ())
done ;
self#discard ()
end
exception Invalid_code of int
let unicode_of_cp1252 =
let mapping =
[|
(* codes from 0x80 to 0x8F: *)
0x20AC ; 0 ; 0x201A ; 0x0192 ; 0x201E ; 0x2026 ; 0x2020 ; 0x2021 ;
0x02C6 ; 0x2030 ; 0x0160 ; 0x2039 ; 0x0152 ; 0 ; 0x017D ; 0 ;
(* codes from 0x90 to 0x9F: *)
0 ; 0x2018 ; 0x2019 ; 0x201C ; 0x201D ; 0x2022 ; 0x2013 ; 0x2014 ;
0x02DC ; 0x2122 ; 0x0161 ; 0x203A ; 0x0153 ; 0 ; 0x017E ; 0x0178 ;
|]
in fun code ->
if 0x80 <= code && code < 0xA0 then
let ucode = mapping.(code-0x80) in
if ucode = 0 then raise (Invalid_code code) else ucode
else
code
let utf8_of_unicode ucode =
assert (ucode < 0b1000000000000000000000) ;
if ucode < 0x80 then
[ ucode ]
else if ucode < 0b100000000000 then
let b1 = 0b10_000000 lor (ucode land 0b111111) in
let b0 = 0b110_00000 lor (ucode lsr 6) in
[ b0 ; b1 ]
else if ucode < 0b10000000000000000 then
let b2 = 0b10_000000 lor ( ucode land 0b111111) in
let b1 = 0b10_000000 lor ((ucode lsr 6 ) land 0b111111) in
let b0 = 0b1110_0000 lor ((ucode lsr 12) ) in
[ b0 ; b1 ; b2 ]
else
let b3 = 0b10_000000 lor (ucode land 0b111111) in
let b2 = 0b10_000000 lor ((ucode lsr 6 ) land 0b111111) in
let b1 = 0b10_000000 lor ((ucode lsr 12) land 0b111111) in
let b0 = 0b11110_000 lor ((ucode lsr 18) ) in
[ b0 ; b1 ; b2 ; b3 ]
let output_utf8_byte =
output_byte stdout
let output_cp1252_as_utf8 code =
try
List.iter output_utf8_byte (utf8_of_unicode (unicode_of_cp1252 code))
with Invalid_code _ ->
Printf.eprintf "unknown code %02X ; inserting “%s” instead\n" code substitute ;
output_string stdout substitute
let rec read state =
match buf#input () with
| b when b < 0x80 && state = 0 ->
buf#discard () ;
output_utf8_byte b ;
read 0
| b when b lsr 6 = 0b10 && state > 0 ->
if state = 1 then
buf#consume output_utf8_byte ;
read (state - 1)
| b when b lsr 5 = 0b110 && state = 0 -> read 1
| b when b lsr 4 = 0b1110 && state = 0 -> read 2
| b when b lsr 3 = 0b11110 && state = 0 -> read 3
| _ ->
buf#consume ~keep:1 output_cp1252_as_utf8 ;
read 0
| exception End_of_file when state > 0 ->
buf#consume ~keep:1 output_cp1252_as_utf8 ;
read 0
| exception End_of_file -> ()
let () =
read 0
#!/bin/sh
# Launches a command out of the terminal.
# If coming from or going to a terminal, input and/or output are discarded.
#
# Usage:
# launch CMD …
# If the command is not available, exit with a detailed error message.
command -v "$1" >&- || "$1"
# Close file descriptors if needed.
if [ -t 0 ]; then
exec 0<&-
fi
if [ -t 1 ]; then
exec 1>&-
fi
# This one simply hides the messages from nohup (as nohup already
# redirects the stderr of the called program to its stdout):
exec 2>&-
# Launch the command.
nohup "$@" &
#!/bin/sh
# Merge recursively a directory into another.
# mvmerge SRCDIR TARGETDIR
# It moves recursively every file from the source directory to the target
# directory (asking for confirmation before overwriting) and preserves
# directory structure. Symbolic links are treated as regular files.
# Note: to copy instead of moving, one can simply run:
# cp -Triv SRCDIR TARGETDIR
if [ -n "$1" -a -n "$2" ] ; then
SOURCE_DIR="$1"
TARGET_DIR="$2"
else
echo "Usage: $0 src dest"
exit
fi
export SOURCE_DIR
export TARGET_DIR
export mvmerge="$(basename "$0")"
# Test whether the given name exists and is really a directory (not a symlink).
function is_true_dir() {
[ -d "$1" -a ! -L "$1" ]
}
# Test whether both the source and the target exist and are directories.
function test_dirs() {
src="$1"
dst="${src/$SOURCE_DIR/$TARGET_DIR}"
#[ -d "$src" -a -d "$dst" ] && [ ! -L "$src" -a ! -L "$dst" ]
is_true_dir "$src" && is_true_dir "$dst"
}
# Rename the source to the target, with interactive overwriting (and verbose
# output) that works even if both files are of different kind (ie. directory or
# non-directory).
function mv_overwrite() {
src="$1"
dst="${src/$SOURCE_DIR/$TARGET_DIR}"
# Here, we know that $src exists, and that $src and $dst can not be both
# directories.
if [ -e "$dst" ]; then
# If $dst exists and is not of the same kind than $src, then ‘mv’ will
# fail to overwrite it. Thus we remove it first.
if is_true_dir "$src"; then
echo -n "$mvmerge: replace the non-directory “$dst” by a directory? " >&2
rm -iv -- "$dst" 2>&-
[ -e "$dst" ] && return # if the user declined
elif is_true_dir "$dst"; then
echo -n "$mvmerge: replace the directory “$dst” by a non-directory? " >&2
rm -rIv -- "$dst" 2>&-
[ -e "$dst" ] && return # if the user declined
fi
fi
mv -Tiv -- "$src" "$dst"
}
export -f is_true_dir
export -f test_dirs
export -f mv_overwrite
# Move every file recursively; if the target exists and both source and target
# are directories, do nothing and let ‘find’ explore them recursively;
# otherwise, move the source to the target and stop the recursion (‘-prune’):
find -- "$SOURCE_DIR" \
-exec sh -c 'test_dirs "$0"' {} \; \
-o -prune -exec sh -c 'mv_overwrite "$0"' {} \;
# Remove remaining directories, but keep the non-directory files, which come the
# user refusing an overwrite (‘-delete’ do not remove a non-empty directory):
[ -e "$SOURCE_DIR" ] && find -- "$SOURCE_DIR" -type d -delete
#!/bin/sh
# Print the current public IP adress to standard output
# with ‘wget’, from package wget:
#wget -qO- http://www.wgetip.com
# with ‘dig’, from package bind-utils:
dig +short myip.opendns.com @resolver1.opendns.com
This diff is collapsed.
This diff is collapsed.
#!/bin/sh
# Take a screenshot.
# Usage: screenshot [root|active] (defaults to root)
SCREEN_DIR=~/Documents/Images/Screenshots/
SCREEN_PROMPT=yes # Ask for a custom filename with i3-input?
DATE=yes # Save date in the filename?
window='root'
case "$1" in
'root')
window='root'
;;
'active')
if ! which xprop; then
i3-nagbar -t error -m 'Capturing a specific window requires the program ‘xprop.’'
exit
fi
window=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | cut -d' ' -f5`
;;
esac
[ "$SCREEN_PROMPT" == "yes" ] && \
name=`i3-input -P 'screen name: ' | sed -n '/command = /s/command = //p'`
if [ -z "$name" ];then
if [ "$window" == "root" ]; then
name='root'
else
name=`xprop -id "$window" | sed -n '/WM_CLASS/s/.* = "\([^\"]*\)".*/\1\n/p'`
[ -z "$name" ] && name='window'
fi
fi
if [ "$DATE" == "yes" ]; then
filename="$name (`date +%Y.%m.%d-%H:%M:%S`).png"
else
filename="$name.png"
fi
# Pause to prevent the i3-input window from being captured on root window.
[ "$SCREEN_PROMPT" == "yes" ] && \
sleep .1
#import -border -frame -window "$window" "$SCREEN_DIR/$filename"
import -window "$window" "$SCREEN_DIR/$filename"
ln -sf "$filename" "$SCREEN_DIR/last"
exit
#!/bin/sh
# Print the color set of the terminal, as well as some other formatting
# escape codes.
#
# ESCAPE CODE SYNTAX:
# \e[xxmTEXT TO ALTER
# Starts with \e[ (or \033[ or \x1B[), then the code (xx), then the m letter.
# Multiple codes can be passed separated by a semicolon (;).
#
# ESCAPE CODES:
# colours:
# 0..7 = the 8 basic colours,
# 8;5;{0..255} = the 256-colours palette (not shown by this script),
# 9 = default color;
# * for background: prefix with 3;
# * for foreground: prefix with 4;
# effects (prefix with 2 to cancel):
# 1 = bold/emphasis (increased intensity),
# 2 = faint (decreased intensity),
# 3 = italic,
# 4 = undelined,
# 5 = slow blink,
# 6 = fast blink,
# 7 = reversed (inverse foreground and background colors),
# 8 = hidden,
# 9 = striked;
# 0 cancels everything.
echo -e '0:\e[00mnormal\e[00m 1:\e[01mbold/emphasis\e[21m 2:\e[02mfaint\e[22m 3:\e[03mitalic\e[23m'
echo -e '4:\e[04munderlined\e[24m blink 5:\e[05mslow\e[25m 6:\e[06mfast\e[26m 7:\e[07mreversed\e[27m'
echo -e '8:\e[08mhidden\e[28m 9:\e[09mstriked\e[29m'
echo -e '10:\e[10mfirst font\e[10m 11:\e[11malt font 1\e[10m 12:\e[12malt font 2\e[0m'
echo -e '51:\e[51mframed\e[54m 52:\e[52mencircled\e[54m 53:\e[53moverlined\e[55m'
colors=(' black ' ' red ' ' green ' 'yellow '
' blue ' 'magenta' ' cyan ' ' white '
'256col ' 'default')
echo -ne "\n "
for j in 9 {0..7}; do
echo -n "${colors[j]} "
done
echo -ne "\n "
for j in 9 {0..7}; do
echo -ne " 4$j "
done
echo
for i in 9 {0..7}; do
for k in ' ' '1;'; do
echo -ne " ${k}3${i} \e[${k}3${i}m"
for j in 9 {0..7}; do
echo -ne "\e[4${j}m Kaï \e[49m "
done
echo -e "\e[0m"
done
done
#!/bin/sh
# ANSI color scheme script featuring Space Invaders
#
# Original: http://crunchbanglinux.org/forums/post/126921/#p126921
# Modified by lolilolicon
#
f=3 b=4
for j in f b; do
for i in {0..7}; do
printf -v $j$i %b "\e[${!j}${i}m"
done
done
bld=$'\e[1m'
rst=$'\e[0m'
cat << EOF
$f1 ▀▄ ▄▀ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4 ▀▄ ▄▀ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
$f1 ▄█▀███▀█▄ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4 ▄█▀███▀█▄ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
$f1█▀███████▀█ $f2▀▀███▀▀███▀▀ $f3▀█▀██▀█▀ $f4█▀███████▀█ $f5▀▀███▀▀███▀▀ $f6▀█▀██▀█▀$rst
$f1▀ ▀▄▄ ▄▄▀ ▀ $f2 ▀█▄ ▀▀ ▄█▀ $f3▀▄ ▄▀ $f4▀ ▀▄▄ ▄▄▀ ▀ $f5 ▀█▄ ▀▀ ▄█▀ $f6▀▄ ▄▀$rst
$bld$f1▄ ▀▄ ▄▀ ▄ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4▄ ▀▄ ▄▀ ▄ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst
$bld$f1█▄█▀███▀█▄█ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4█▄█▀███▀█▄█ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst
$bld$f1▀█████████▀ $f2▀▀▀██▀▀██▀▀▀ $f3▀▀█▀▀█▀▀ $f4▀█████████▀ $f5▀▀▀██▀▀██▀▀▀ $f6▀▀█▀▀█▀▀$rst
$bld$f1 ▄▀ ▀▄ $f2▄▄▀▀ ▀▀ ▀▀▄▄ $f3▄▀▄▀▀▄▀▄ $f4 ▄▀ ▀▄ $f5▄▄▀▀ ▀▀ ▀▀▄▄ $f6▄▀▄▀▀▄▀▄$rst
$f7$rst
$f7$rst
$f7 ▄█▄ $rst
$f7▄█████████▄$rst
$f7▀▀▀▀▀▀▀▀▀▀▀$rst
EOF
#!/bin/sh
# Show the terminal’s 256-colors palette, foreground and background.
for fgbg in 38 48 ; do
for color in {0..255} ; do
# 0..15: standard xterm colors (0..7: normal, 8..15: highlight)
if [ $color -lt 16 ] ; then
[ $color -eq 8 ] && echo
fgcolor=$(( ($color + 8) % 16 ))
rgbcode=
# 16..231: RGB colors (six-valued components ranging in 0..5)
elif [ $color -lt 232 ] ; then
[ $(( $color % 6 )) -eq 4 ] && echo
colord=$(( $color - 16 ))
r=$(( $colord / 36 ))
g=$(( ($colord / 6) % 6 ))
b=$(( $colord % 6 ))
if [ $(( $r+$g+$b )) -le 4 ] ; then
fgcolor=255 # white
else
fgcolor=232 # black
fi
rgbcode="$r$g$b"
# 232..255: twenty-four shades of grey (from black to white)
else
[ $(( $color % 8 )) -eq 0 ] && echo
if [ $color -lt 244 ] ; then
fgcolor=255 # white
else
fgcolor=232 # black
fi
rgbcode=
fi
printf '\e[38;5;%s;%s;5;%s;1m%7s\e[21;3m%s \e[0m' $fgcolor $fgbg $color $color "$rgbcode"
done
echo
echo
done
#!/bin/sh
# output names (run ‘xrandr’ to find them):
INTERNAL='eDP1'
EXTERNAL='HDMI1'
# position of the external output with respect to the internal
# (one of left-of, right-of, above, below, same-as):
LOCATION='right-of'
FILE=/tmp/toggle_screen
# Is external output connected?
if xrandr | grep "$EXTERNAL connected" >/dev/null ; then
# Cycle between three modes : only INT, only EXT, INT and EXT.
# TODO get state with xrandr | grep "*"
mode=$([ -f "$FILE" ] && cat "$FILE")
case "$mode" in
'both')
new_mode=ext
xrandr --output $INTERNAL --off --output $EXTERNAL --auto
;;
'ext')
new_mode=int
xrandr --output $INTERNAL --auto --output $EXTERNAL --off
;;
'int' | *)
new_mode=both
xrandr --output $INTERNAL --auto --output $EXTERNAL --auto --$LOCATION $INTERNAL
;;
esac
echo $new_mode > $FILE
else
xrandr --auto
fi
#!/bin/sh
# Runs top on the alternate screen (for xterm-based terminals), to fix its
# less-like behaviour (that is, leave the normal console buffer unaltered).
# ArchLinux’s top does not use the alternate screen by itself, but it does
# clear the screen when it starts (which is annoying), and misses to do it
# again when it leaves (which is annoying to).
#
# See here for xterm control sequences:
# http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
if [ -t 1 ]; then # Do not do that if output is not a terminal.
echo -ne '\e[?1049h' # Toggle alternate screen on (clearing its contents).
/usr/bin/top "$@"
echo -ne '\e[?1049l' # Toggle alternate screen off (clearing it again).
else
/usr/bin/top "$@"
fi
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment