commit 0ac22ca91e425138edfd59a0dc77215d7851db05 Author: Anton Lydike Date: Fri Jan 31 17:20:18 2020 +0100 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/bin/.bin b/bin/.bin new file mode 120000 index 0000000..ca43046 --- /dev/null +++ b/bin/.bin @@ -0,0 +1 @@ +/home/anton/.bin \ No newline at end of file diff --git a/bin/bat-state b/bin/bat-state new file mode 100755 index 0000000..2fb9075 --- /dev/null +++ b/bin/bat-state @@ -0,0 +1,83 @@ +#!/usr/bin/env fish +# listen to battery state and warn on low battery + +# read low battery state level from environment and fallback to a value of 8 +set LOW 8 +test -n "$BAT_CRITICAL_LEVEL" -a "$BAT_CRITICAL_LEVEL" -gt 0; and set LOW "$BAT_CRITICAL_LEVEL" + +# read config from environment +set ALARM_TEMP 1000 +test -z "$BAT_ALARM_TEMP" -a "$BAT_ALARM_TEMP" -gt 1000; and set ALARM_TEMP "$BAT_ALARM_TEMP" + +# if we are currently below or above our LOW threshold +set isLow "false" + +# print config +echo "Set up with LOW=$LOW and ALARM_TEMP=$ALARM_TEMP" +#echo "redshift="(which redshift) + +function check_btry + set state (upower -i /org/freedesktop/UPower/devices/battery_BAT0 | rg "(percent|state)" | awk -F " " '{print $2}') + + set charge (echo "$state[2]" | string replace "%" "") + set state "$state[1]" + + set c_low (test "$charge" -lt "$LOW"; and echo true; or echo false) + + if test $c_low = true; and test $state = discharging; and test $isLow != true + echo "transitioning to low battery state" + low_btry_action + set isLow true + else if test ! $state = discharging; and test $isLow != false + echo "transtioning to high bat state (charger)" + set isLow false + high_btry_action + else if test $c_low = false; and test $isLow != false + echo "transitioning to high bat state (magic)" + set isLow false + high_btry_action + end +end + + +function low_btry_action + # kill redshift job and set fixed alarm temp + if jobs -q + echo killing redshift with pid (jobs -p) + kill (jobs -p) + end + redshift -P -O "$ALARM_TEMP" +end + +function high_btry_action + # start redshift again + + redshift -P -l 50.11552:8.68417 -t 5500:2500 & +end + + +if test "$argv[1]" = once + check_btry + + set state (upower -i /org/freedesktop/UPower/devices/battery_BAT0 | rg "(percent|state)" | awk -F " " '{print $2}') + + set charge (echo "$state[2]" | string replace "%" "") + set state "$state[1]" + + echo "$charge : $state" +else + #set percent (upower -i /org/freedesktop/UPower/devices/battery_BAT0 | rg "(percent)" | awk -F " " '{print $2}' | string replace "%" "") + + # set initial isLow variable to the opposite of what it's supposed to be to trigger a + #test "$percent" -lt "$LOW"; and set isLow "false" + set isLow unknown + + sleep 5 + + while true + check_btry + sleep (test $isLow = true; and echo 1; or echo 60) + end +end + + diff --git a/bin/brightness b/bin/brightness new file mode 100755 index 0000000..6a20a95 --- /dev/null +++ b/bin/brightness @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + +import sys, os + +# config: +# put your device here +device="/sys/class/backlight/amdgpu_bl0/" + +def smart_int(num): + if (num[0] == '+'): return int(num[1:]) + return int(num) + +def do_action(action): + if (action == 'show'): + curr = get_current() + _max = get_max() + print('screen brightness is at %s (%d/%d)' % (str(int(curr / _max * 100)), curr, _max)); + return + if (action[-1:] == '%'): + if (action[0] == "+" or action[0] == '-'): + curr = get_current() + max = get_max() + curr_pc = curr / max * 100 + put_brightness(int(max * ((curr_pc + smart_int(action[:-1])) / 100))) + else: + put_brightness(int(get_max() * (int(action[:-1]) / 100))) + + elif (action[0] == '+' or action[0] == "-"): + put_brightness(get_current() + smart_int(action)) + elif (action.isdigit()): + put_brightness(int(action)) + +def get_current(): + with open(device + 'brightness', 'r') as f: + return int(f.read().replace('\n', '')) + +def put_brightness(ammount): + ammount = num_in_range(ammount) + print("screen brightnes is " + str(ammount)); + with open(device + 'brightness', 'r+') as f: + f.write(str(ammount)) + +def get_max(): + with open(device + 'max_brightness', 'r') as f: + return int(f.read().replace('\n', '')) + +def num_in_range(num): + max = get_max() + if (num > max): num = max + if (num < 0): num = 0 + return num + + +for action in sys.argv[1::]: do_action(action) diff --git a/bin/dgc b/bin/dgc new file mode 120000 index 0000000..d46680c --- /dev/null +++ b/bin/dgc @@ -0,0 +1 @@ +/home/anton/projects/diggicamp/diggicamp-nix.sh \ No newline at end of file diff --git a/bin/fff b/bin/fff new file mode 100755 index 0000000..d6e7876 --- /dev/null +++ b/bin/fff @@ -0,0 +1,1111 @@ +#!/usr/bin/env bash +# +# fff - fucking fast file-manager. + +get_os() { + # Figure out the current operating system to set some specific variables. + # '$OSTYPE' typically stores the name of the OS kernel. + case "$OSTYPE" in + # Mac OS X / macOS. + darwin*) + opener="open" + file_flags="bIL" + ;; + + haiku) + opener="open" + + [[ -z $FFF_TRASH_CMD ]] && + FFF_TRASH_CMD="trash" + + [[ $FFF_TRASH_CMD == trash ]] && { + FFF_TRASH="$(finddir -v "$PWD" B_TRASH_DIRECTORY)" + mkdir -p "$FFF_TRASH" + } + ;; + esac +} + +setup_terminal() { + # Setup the terminal for the TUI. + # '\e[?1049h': Use alternative screen buffer. + # '\e[?7l': Disable line wrapping. + # '\e[?25l': Hide the cursor. + # '\e[2J': Clear the screen. + # '\e[1;Nr': Limit scrolling to scrolling area. + # Also sets cursor to (0,0). + printf '\e[?1049h\e[?7l\e[?25l\e[2J\e[1;%sr' "$max_items" + + # Hide echoing of user input + stty -echo +} + +reset_terminal() { + # Reset the terminal to a useable state (undo all changes). + # '\e[?7h': Re-enable line wrapping. + # '\e[?25h': Unhide the cursor. + # '\e[2J': Clear the terminal. + # '\e[;r': Set the scroll region to its default value. + # Also sets cursor to (0,0). + # '\e[?1049l: Restore main screen buffer. + printf '\e[?7h\e[?25h\e[2J\e[;r\e[?1049l' + + # Show user input. + stty echo +} + +clear_screen() { + # Only clear the scrolling window (dir item list). + # '\e[%sH': Move cursor to bottom of scroll area. + # '\e[9999C': Move cursor to right edge of the terminal. + # '\e[1J': Clear screen to top left corner (from cursor up). + # '\e[2J': Clear screen fully (if using tmux) (fixes clear issues). + # '\e[1;%sr': Clearing the screen resets the scroll region(?). Re-set it. + # Also sets cursor to (0,0). + printf '\e[%sH\e[9999C\e[1J%b\e[1;%sr' \ + "$((LINES-2))" "${TMUX:+\e[2J}" "$max_items" +} + +setup_options() { + # Some options require some setup. + # This function is called once on open to parse + # select options so the operation isn't repeated + # multiple times in the code. + + # Format for normal files. + [[ $FFF_FILE_FORMAT == *%f* ]] && { + file_pre="${FFF_FILE_FORMAT/'%f'*}" + file_post="${FFF_FILE_FORMAT/*'%f'}" + } + + # Format for marked files. + [[ $FFF_MARK_FORMAT == *%f* ]] && { + mark_pre="${FFF_MARK_FORMAT/'%f'*}" + mark_post="${FFF_MARK_FORMAT/*'%f'}" + } +} + +get_term_size() { + # Get terminal size ('stty' is POSIX and always available). + # This can't be done reliably across all bash versions in pure bash. + read -r LINES COLUMNS < <(stty size) + + # Max list items that fit in the scroll area. + ((max_items=LINES-3)) +} + +get_ls_colors() { + # Parse the LS_COLORS variable and declare each file type + # as a separate variable. + # Format: ':.ext=0;0:*.jpg=0;0;0:*png=0;0;0;0:' + [[ -z $LS_COLORS ]] && { + FFF_LS_COLORS=0 + return + } + + # Turn $LS_COLORS into an array. + IFS=: read -ra ls_cols <<< "$LS_COLORS" + + for ((i=0;i<${#ls_cols[@]};i++)); { + # Separate patterns from file types. + [[ ${ls_cols[i]} =~ ^\*[^\.] ]] && + ls_patterns+="${ls_cols[i]/=*}|" + + # Prepend 'ls_' to all LS_COLORS items + # if they aren't types of files (symbolic links, block files etc.) + [[ ${ls_cols[i]} =~ ^(\*|\.) ]] && { + ls_cols[i]="${ls_cols[i]#\*}" + ls_cols[i]="ls_${ls_cols[i]#.}" + } + } + + # Strip non-ascii characters from the string as they're + # used as a key to color the dir items and variable + # names in bash must be '[a-zA-z0-9_]'. + ls_cols=("${ls_cols[@]//[^a-zA-Z0-9=\\;]/_}") + + # Store the patterns in a '|' separated string + # for use in a REGEX match later. + ls_patterns="${ls_patterns//\*}" + ls_patterns="${ls_patterns%?}" + + # Define the ls_ variables. + # 'declare' can't be used here as variables are scoped + # locally. 'declare -g' is not available in 'bash 3'. + # 'export' is a viable alternative. + export "${ls_cols[@]}" &>/dev/null +} + +get_w3m_path() { + # Find the path to the w3m-img library. + # If w3mimgdisplay is already in path, use it. + type -p w3mimgdisplay &>/dev/null && { + w3m="w3mimgdisplay" + return + } + + # Use a glob and expansion to find the path. + w3m_paths=(/usr/{local/,}{lib,libexec,lib64,libexec64}/w3m/w3mi*) + + [[ -x ${w3m_paths[0]} ]] && + w3m="${w3m_paths[0]}" +} + +get_mime_type() { + # Get a file's mime_type. + mime_type="$(file "-${file_flags:-biL}" "$1")" +} + +status_line() { + # Status_line to print when files are marked for operation. + local mark_ui="[${#marked_files[@]}] selected (${file_program[*]}) [p] ->" + + # Escape the directory string. + # Remove all non-printable characters. + PWD_escaped="${PWD//[^[:print:]]/^[}" + + # '\e7': Save cursor position. + # This is more widely supported than '\e[s'. + # '\e[%sH': Move cursor to bottom of the terminal. + # '\e[30;41m': Set foreground and background colors. + # '%*s': Insert enough spaces to fill the screen width. + # This sets the background color to the whole line + # and fixes issues in 'screen' where '\e[K' doesn't work. + # '\r': Move cursor back to column 0 (was at EOL due to above). + # '\e[m': Reset text formatting. + # '\e[H\e[K': Clear line below status_line. + # '\e8': Restore cursor position. + # This is more widely supported than '\e[u'. + printf '\e7\e[%sH\e[30;4%sm%*s\r%s %s%s\e[m\e[%sH\e[K\e8' \ + "$((LINES-1))" \ + "${FFF_COL2:-1}" \ + "$COLUMNS" "" \ + "($((scroll+1))/$((list_total+1)))" \ + "${marked_files[*]:+${mark_ui}}" \ + "${1:-${PWD_escaped:-/}}" \ + "$LINES" +} + +read_dir() { + # Read a directory to an array and sort it directories first. + local dirs + local files + local item_index + + # If '$PWD' is '/', unset it to avoid '//'. + [[ $PWD == / ]] && PWD= + + for item in "$PWD"/*; do + if [[ -d $item ]]; then + dirs+=("$item") + ((item_index++)) + + # Find the position of the child directory in the + # parent directory list. + [[ $item == "$OLDPWD" ]] && + ((previous_index=item_index)) + else + files+=("$item") + fi + done + + list=("${dirs[@]}" "${files[@]}") + + # Indicate that the directory is empty. + [[ -z ${list[0]} ]] && + list[0]="empty" + + ((list_total=${#list[@]}-1)) + + # Save the original dir in a second list as a backup. + cur_list=("${list[@]}") +} + +print_line() { + # Format the list item and print it. + local file_name="${list[$1]##*/}" + local file_ext="${file_name##*.}" + local format + local suffix + + # If the dir item doesn't exist, end here. + if [[ -z ${list[$1]} ]]; then + return + + # Directory. + elif [[ -d ${list[$1]} ]]; then + format+="\\e[${di:-1;3${FFF_COL1:-2}}m" + suffix+='/' + + # Block special file. + elif [[ -b ${list[$1]} ]]; then + format+="\\e[${bd:-40;33;01}m" + + # Character special file. + elif [[ -c ${list[$1]} ]]; then + format+="\\e[${cd:-40;33;01}m" + + # Executable file. + elif [[ -x ${list[$1]} ]]; then + format+="\\e[${ex:-01;32}m" + + # Symbolic Link (broken). + elif [[ -h ${list[$1]} && ! -e ${list[$1]} ]]; then + format+="\\e[${mi:-01;31;7}m" + + # Symbolic Link. + elif [[ -h ${list[$1]} ]]; then + format+="\\e[${ln:-01;36}m" + + # Fifo file. + elif [[ -p ${list[$1]} ]]; then + format+="\\e[${pi:-40;33}m" + + # Socket file. + elif [[ -S ${list[$1]} ]]; then + format+="\\e[${so:-01;35}m" + + # Color files that end in a pattern as defined in LS_COLORS. + # 'BASH_REMATCH' is an array that stores each REGEX match. + elif [[ $FFF_LS_COLORS == 1 && + $ls_patterns && + $file_name =~ ($ls_patterns)$ ]]; then + match="${BASH_REMATCH[0]}" + file_ext="ls_${match//[^a-zA-Z0-9=\\;]/_}" + format+="\\e[${!file_ext:-${fi:-37}}m" + + # Color files based on file extension and LS_COLORS. + # Check if file extension adheres to POSIX naming + # stardard before checking if it's a variable. + elif [[ $FFF_LS_COLORS == 1 && + $file_ext != "$file_name" && + $file_ext =~ ^[a-zA-Z0-9_]*$ ]]; then + file_ext="ls_${file_ext}" + format+="\\e[${!file_ext:-${fi:-37}}m" + + else + format+="\\e[${fi:-37}m" + fi + + # If the list item is under the cursor. + (($1 == scroll)) && + format+="\\e[1;3${FFF_COL4:-6};7m" + + # If the list item is marked for operation. + [[ ${marked_files[$1]} == "${list[$1]:-null}" ]] && { + format+="\\e[3${FFF_COL3:-1}m${mark_pre:= }" + suffix+="${mark_post:=*}" + } + + # Escape the directory string. + # Remove all non-printable characters. + file_name="${file_name//[^[:print:]]/^[}" + + printf '\r%b%s\e[m\r' \ + "${file_pre}${format}" \ + "${file_name}${suffix}${file_post}" +} + +draw_dir() { + # Print the max directory items that fit in the scroll area. + local scroll_start="$scroll" + local scroll_new_pos + local scroll_end + + # When going up the directory tree, place the cursor on the position + # of the previous directory. + ((find_previous == 1)) && { + ((scroll_start=previous_index-1)) + ((scroll=scroll_start)) + + # Clear the directory history. We're here now. + find_previous= + } + + # If current dir is near the top of the list, keep scroll position. + if ((list_total < max_items || scroll < max_items/2)); then + ((scroll_start=0)) + ((scroll_end=max_items)) + ((scroll_new_pos=scroll + 1)) + + # If curent dir is near the end of the list, keep scroll position. + elif ((list_total - scroll < max_items/2)); then + ((scroll_start=list_total - max_items + 1)) + ((scroll_new_pos=max_items - (list_total-scroll))) + ((scroll_end=list_total+1)) + + # If current dir is somewhere in the middle, center scroll position. + else + ((scroll_start=scroll-max_items/2)) + ((scroll_end=scroll_start+max_items)) + ((scroll_new_pos=max_items/2+1)) + fi + + # Reset cursor position. + printf '\e[H' + + for ((i=scroll_start;i scroll_start)) && + printf '\n' + + print_line "$i" + } + + # Move the cursor to its new position if it changed. + # If the variable 'scroll_new_pos' is empty, the cursor + # is moved to line '0'. + printf '\e[%sH' "$scroll_new_pos" + ((y=scroll_new_pos)) +} + +draw_img() { + # Draw an image file on the screen using w3m-img. + # We can use the framebuffer; set win_info_cmd as appropriate. + [[ $(tty) == /dev/tty[0-9]* && -w /dev/fb0 ]] && + win_info_cmd="fbset" + + # X isn't running and we can't use the framebuffer, do nothing. + [[ -z $DISPLAY && $win_info_cmd != fbset ]] && + return + + # File isn't an image file, do nothing. + get_mime_type "${list[scroll]}" + [[ $mime_type != image/* ]] && + return + + # w3m-img isn't installed, do nothing. + type -p "$w3m" &>/dev/null || { + cmd_line "error: Couldn't find 'w3m-img', is it installed?" + return + } + + # $win_info_cmd isn't installed, do nothing. + type -p "${win_info_cmd:=xdotool}" &>/dev/null || { + cmd_line "error: Couldn't find '$win_info_cmd', is it installed?" + return + } + + # Get terminal window size in pixels and set it to WIDTH and HEIGHT. + if [[ $win_info_cmd == xdotool ]]; then + IFS=$'\n' read -d "" -ra win_info \ + < <(xdotool getactivewindow getwindowgeometry --shell) + + declare "${win_info[@]}" &>/dev/null || { + cmd_line "error: Failed to retrieve window size." + return + } + else + [[ $(fbset --show) =~ .*\"([0-9]+x[0-9]+)\".* ]] + IFS=x read -r WIDTH HEIGHT <<< "${BASH_REMATCH[1]}" + fi + + # Get the image size in pixels. + read -r img_width img_height < <("$w3m" <<< "5;${list[scroll]}") + + # Substract the status_line area from the image size. + ((HEIGHT=HEIGHT-HEIGHT*5/LINES)) + + ((img_width > WIDTH)) && { + ((img_height=img_height*WIDTH/img_width)) + ((img_width=WIDTH)) + } + + ((img_height > HEIGHT)) && { + ((img_width=img_width*HEIGHT/img_height)) + ((img_height=HEIGHT)) + } + + clear_screen + status_line "${list[scroll]}" + + # Add a small delay to fix issues in VTE terminals. + ((BASH_VERSINFO[0] > 3)) && + read "${read_flags[@]}" -srn 1 + + # Display the image. + printf '0;1;%s;%s;%s;%s;;;;;%s\n3;\n4\n' \ + "${FFF_W3M_XOFFSET:-0}" \ + "${FFF_W3M_YOFFSET:-0}" \ + "$img_width" \ + "$img_height" \ + "${list[scroll]}" | "$w3m" &>/dev/null + + # Wait for user input. + read -ern 1 + + # Clear the image. + printf '6;%s;%s;%s;%s\n3;' \ + "${FFF_W3M_XOFFSET:-0}" \ + "${FFF_W3M_YOFFSET:-0}" \ + "$WIDTH" \ + "$HEIGHT" | "$w3m" &>/dev/null + + redraw +} + +redraw() { + # Redraw the current window. + # If 'full' is passed, re-fetch the directory list. + [[ $1 == full ]] && { + read_dir + scroll=0 + } + + clear_screen + draw_dir + status_line +} + +run() { + # Run a program without disrupting the user-interface. + clear_screen + reset_terminal + "$@" + setup_terminal + redraw +} + +mark() { + # Mark file for operation. + # If an item is marked in a second directory, + # clear the marked files. + [[ $PWD != "$mark_dir" ]] && + marked_files=() + + # Don't allow the user to mark the empty directory list item. + [[ ${list[0]} == empty && -z ${list[1]} ]] && + return + + if [[ $1 == all ]]; then + if ((${#marked_files[@]} != ${#list[@]})); then + marked_files=("${list[@]}") + mark_dir="$PWD" + else + marked_files=() + fi + + redraw + else + if [[ ${marked_files[$1]} == "${list[$1]}" ]]; then + unset 'marked_files[scroll]' + + else + marked_files[$1]="${list[$1]}" + mark_dir="$PWD" + fi + + # Clear line before changing it. + printf '\e[K' + print_line "$1" + fi + + # Find the program to use. + case "$2" in + y|Y) file_program=(cp -iR) ;; + m|M) file_program=(mv -i) ;; + s|S) file_program=(ln -s) ;; + + # These are 'fff' functions. + d|D) file_program=(trash) ;; + b|B) file_program=(bulk_rename) ;; + esac + + status_line +} + +trash() { + # 'trash' a file. + cmd_line "trash [${#marked_files[@]}] items? [y/n]: " y n + + [[ $cmd_reply != y ]] && + return + + if [[ $FFF_TRASH_CMD ]]; then + # Pass all but the last argument to the user's + # custom script. command is used to prevent this function + # from conflicting with commands named "trash". + command "$FFF_TRASH_CMD" "${@:1:$#-1}" + + else + cd "$FFF_TRASH" && mv -f "$@" + + # Go back to where we were. + cd "$OLDPWD" ||: + fi +} + +bulk_rename() { + # Bulk rename files using '$EDITOR'. + rename_file="${XDG_CACHE_HOME:=${HOME}/.cache}/fff/bulk_rename" + marked_files=("${@:1:$#-1}") + + # Save marked files to a file and open them for editing. + printf '%s\n' "${marked_files[@]##*/}" > "$rename_file" + "${EDITOR:-vi}" "$rename_file" + + # Read the renamed files to an array. + IFS=$'\n' read -d "" -ra changed_files < "$rename_file" + + # If the user deleted a line, stop here. + ((${#marked_files[@]} != ${#changed_files[@]})) && { + rm "$rename_file" + cmd_line "error: Line mismatch in rename file. Doing nothing." + return + } + + printf '%s\n%s\n' \ + "# This file will be executed when the editor is closed." \ + "# Clear the file to abort." > "$rename_file" + + # Construct the rename commands. + for ((i=0;i<${#marked_files[@]};i++)); { + [[ ${marked_files[i]} != "${PWD}/${changed_files[i]}" ]] && { + printf 'mv -i -- %q %q\n' \ + "${marked_files[i]}" "${PWD}/${changed_files[i]}" + local renamed=1 + } + } >> "$rename_file" + + # Let the user double-check the commands and execute them. + ((renamed == 1)) && { + "${EDITOR:-vi}" "$rename_file" + + source "$rename_file" + rm "$rename_file" + } + + # Fix terminal settings after '$EDITOR'. + setup_terminal +} + +open() { + # Open directories and files. + if [[ -d $1/ ]]; then + search= + search_end_early= + cd "${1:-/}" ||: + redraw full + + elif [[ -f $1 ]]; then + # Figure out what kind of file we're working with. + get_mime_type "$1" + + # Open all text-based files in '$EDITOR'. + # Everything else goes through 'xdg-open'/'open'. + case "$mime_type" in + text/*|*x-empty*|*json*) + # If 'fff' was opened as a file picker, save the opened + # file in a file called 'opened_file'. + ((file_picker == 1)) && { + printf '%s\n' "$1" > \ + "${XDG_CACHE_HOME:=${HOME}/.cache}/fff/opened_file" + exit + } + + run "${VISUAL:-${EDITOR:-vi}}" "$1" + ;; + + *) + # 'nohup': Make the process immune to hangups. + # '&': Send it to the background. + # 'disown': Detach it from the shell. + if type -p "$FFF_OPENER" &>/dev/null; then + run "$FFF_OPENER" "$1" + + else + nohup "${opener:-xdg-open}" "$1" &>/dev/null & disown + fi + ;; + esac + fi +} + +cmd_line() { + # Write to the command_line (under status_line). + cmd_reply= + + # '\e7': Save cursor position. + # '\e[?25h': Unhide the cursor. + # '\e[%sH': Move cursor to bottom (cmd_line). + printf '\e7\e[%sH\e[?25h' "$LINES" + + # '\r\e[K': Redraw the read prompt on every keypress. + # This is mimicking what happens normally. + while IFS= read -rsn 1 -p $'\r\e[K'"${1}${cmd_reply}" read_reply; do + case "$read_reply" in + # Backspace. + $'\177'|$'\b') + cmd_reply="${cmd_reply%?}" + + # Clear tab-completion. + unset comp c + ;; + + # Tab. + $'\t') + comp_glob="$cmd_reply*" + + # Pass the argument dirs to limit completion to directories. + [[ $2 == dirs ]] && + comp_glob="$cmd_reply*/" + + # Generate a completion list once. + [[ -z ${comp[0]} ]] && + IFS=$'\n' read -d "" -ra comp < <(compgen -G "$comp_glob") + + # On each tab press, cycle through the completion list. + [[ -n ${comp[c]} ]] && { + cmd_reply="${comp[c]}" + ((c=c >= ${#comp[@]}-1 ? 0 : ++c)) + } + ;; + + # Escape / Custom 'no' value (used as a replacement for '-n 1'). + $'\e'|"${3:-null}") + cmd_reply= + break + ;; + + # Enter/Return. + "") + # If there's only one search result and its a directory, + # enter it on one enter keypress. + [[ $2 == search && -d ${list[0]} ]] && ((list_total == 0)) && { + # '\e[?25l': Hide the cursor. + printf '\e[?25l' + + open "${list[0]}" + search_end_early=1 + + # Unset tab completion variables since we're done. + unset comp c + return + } + + break + ;; + + # Custom 'yes' value (used as a replacement for '-n 1'). + "${2:-null}") + cmd_reply="$read_reply" + break + ;; + + # Replace '~' with '$HOME'. + "~") + cmd_reply+="$HOME" + ;; + + # Anything else, add it to read reply. + *) + cmd_reply+="$read_reply" + + # Clear tab-completion. + unset comp c + ;; + esac + + # Search on keypress if search passed as an argument. + [[ $2 == search ]] && { + # '\e[?25l': Hide the cursor. + printf '\e[?25l' + + # Use a greedy glob to search. + list=("$PWD"/*"$cmd_reply"*) + ((list_total=${#list[@]}-1)) + + # Draw the search results on screen. + scroll=0 + redraw + + # '\e[%sH': Move cursor back to cmd-line. + # '\e[?25h': Unhide the cursor. + printf '\e[%sH\e[?25h' "$LINES" + } + done + + # Unset tab completion variables since we're done. + unset comp c + + # '\e[2K': Clear the entire cmd_line on finish. + # '\e[?25l': Hide the cursor. + # '\e8': Restore cursor position. + printf '\e[2K\e[?25l\e8' +} + +key() { + # Handle special key presses. + [[ $1 == $'\e' ]] && { + read "${read_flags[@]}" -rsn 2 + + # Handle a normal escape key press. + [[ ${1}${REPLY} == $'\e\e['* ]] && + read "${read_flags[@]}" -rsn 1 _ + + local special_key="${1}${REPLY}" + } + + case "${special_key:-$1}" in + # Open list item. + # 'C' is what bash sees when the right arrow is pressed ('\e[C'). + # '' is what bash sees when the enter/return key is pressed. + "${FFF_KEY_CHILD1:=l}"|\ + "${FFF_KEY_CHILD2:=$'\e[C'}"|\ + "${FFF_KEY_CHILD3:=""}") + open "${list[scroll]}" + ;; + + # Go to the parent directory. + # 'D' is what bash sees when the left arrow is pressed ('\e[D'). + # '\177' and '\b' are what bash sometimes sees when the backspace + # key is pressed. + "${FFF_KEY_PARENT1:=h}"|\ + "${FFF_KEY_PARENT2:=$'\e[D'}"|\ + "${FFF_KEY_PARENT3:=$'\177'}"|\ + "${FFF_KEY_PARENT4:=$'\b'}") + # If a search was done, clear the results and open the current dir. + if ((search == 1 && search_end_early != 1)); then + open "$PWD" + + # If '$PWD' is '/', do nothing. + elif [[ $PWD && $PWD != / ]]; then + find_previous=1 + open "${PWD%/*}" + fi + ;; + + # Scroll down. + # 'B' is what bash sees when the down arrow is pressed ('\e[B'). + "${FFF_KEY_SCROLL_DOWN1:=j}"|\ + "${FFF_KEY_SCROLL_DOWN2:=$'\e[B'}") + ((scroll < list_total)) && { + ((scroll++)) + ((y < max_items)) && ((y++)) + + print_line "$((scroll-1))" + printf '\n' + print_line "$scroll" + status_line + } + ;; + + # Scroll up. + # 'A' is what bash sees when the up arrow is pressed ('\e[A'). + "${FFF_KEY_SCROLL_UP1:=k}"|\ + "${FFF_KEY_SCROLL_UP2:=$'\e[A'}") + # '\e[1L': Insert a line above the cursor. + # '\e[A': Move cursor up a line. + ((scroll > 0)) && { + ((scroll--)) + + print_line "$((scroll+1))" + + if ((y < 2)); then + printf '\e[L' + else + printf '\e[A' + ((y--)) + fi + + print_line "$scroll" + status_line + } + ;; + + # Go to top. + "${FFF_KEY_TO_TOP:=g}") + ((scroll != 0)) && { + scroll=0 + redraw + } + ;; + + # Go to bottom. + "${FFF_KEY_TO_BOTTOM:=G}") + ((scroll != list_total)) && { + ((scroll=list_total)) + redraw + } + ;; + + # Show hidden files. + "${FFF_KEY_HIDDEN:=.}") + # 'a=a>0?0:++a': Toggle between both values of 'shopt_flags'. + # This also works for '3' or more values with + # some modification. + shopt_flags=(u s) + shopt -"${shopt_flags[((a=a>0?0:++a))]}" dotglob + redraw full + ;; + + # Search. + "${FFF_KEY_SEARCH:=/}") + cmd_line "/" "search" + + # If the search came up empty, redraw the current dir. + if [[ -z ${list[*]} ]]; then + list=("${cur_list[@]}") + ((list_total=${#list[@]}-1)) + redraw + search= + else + search=1 + fi + ;; + + # Spawn a shell. + "${FFF_KEY_SHELL:=!}") + reset_terminal + + # Make fff aware of how many times it is nested. + export FFF_LEVEL + ((FFF_LEVEL++)) + + cd "$PWD" && "$SHELL" + setup_terminal + redraw + ;; + + # Mark files for operation. + "${FFF_KEY_YANK:=y}"|\ + "${FFF_KEY_MOVE:=m}"|\ + "${FFF_KEY_TRASH:=d}"|\ + "${FFF_KEY_LINK:=s}"|\ + "${FFF_KEY_BULK_RENAME:=b}") + mark "$scroll" "$1" + ;; + + # Mark all files for operation. + "${FFF_KEY_YANK_ALL:=Y}"|\ + "${FFF_KEY_MOVE_ALL:=M}"|\ + "${FFF_KEY_TRASH_ALL:=D}"|\ + "${FFF_KEY_LINK_ALL:=S}"|\ + "${FFF_KEY_BULK_RENAME_ALL:=B}") + mark all "$1" + ;; + + # Do the file operation. + "${FFF_KEY_PASTE:=p}") + [[ ${marked_files[*]} ]] && { + [[ ! -w $PWD ]] && { + cmd_line "warn: no write access to dir." + return + } + + # Clear the screen to make room for a prompt if needed. + clear_screen + reset_terminal + + stty echo + "${file_program[@]}" "${marked_files[@]}" . + stty -echo + + marked_files=() + setup_terminal + redraw full + } + ;; + + # Clear all marked files. + "${FFF_KEY_CLEAR:=c}") + [[ ${marked_files[*]} ]] && { + marked_files=() + redraw + } + ;; + + # Rename list item. + "${FFF_KEY_RENAME:=r}") + [[ ! -e "${list[scroll]}" ]] && + return + + cmd_line "rename ${list[scroll]##*/}: " + + [[ $cmd_reply ]] && + if [[ -e $cmd_reply ]]; then + cmd_line "warn: '$cmd_reply' already exists." + + elif [[ -w ${list[scroll]} ]]; then + mv "${list[scroll]}" "${PWD}/${cmd_reply}" + redraw full + + else + cmd_line "warn: no write access to file." + fi + ;; + + # Create a directory. + "${FFF_KEY_MKDIR:=n}") + cmd_line "mkdir: " "dirs" + + [[ $cmd_reply ]] && + if [[ -e $cmd_reply ]]; then + cmd_line "warn: '$cmd_reply' already exists." + + elif [[ -w $PWD ]]; then + mkdir -p "${PWD}/${cmd_reply}" + redraw full + + else + cmd_line "warn: no write access to dir." + fi + ;; + + # Create a file. + "${FFF_KEY_MKFILE:=f}") + cmd_line "mkfile: " + + [[ $cmd_reply ]] && + if [[ -e $cmd_reply ]]; then + cmd_line "warn: '$cmd_reply' already exists." + + elif [[ -w $PWD ]]; then + : > "$cmd_reply" + redraw full + + else + cmd_line "warn: no write access to dir." + fi + ;; + + # Show file attributes. + "${FFF_KEY_ATTRIBUTES:=x}") + [[ -e "${list[scroll]}" ]] && { + clear_screen + status_line "${list[scroll]}" + stat "${list[scroll]}" + read -ern 1 + redraw + } + ;; + + # Show image in terminal. + "${FFF_KEY_IMAGE:=i}") + draw_img + ;; + + # Go to dir. + "${FFF_KEY_GO_DIR:=:}") + cmd_line "go to dir: " "dirs" + + # Let 'cd' know about the current directory. + cd "$PWD" &>/dev/null ||: + + [[ $cmd_reply ]] && + cd "${cmd_reply/\~/$HOME}" &>/dev/null && + open "$PWD" + ;; + + # Go to '$HOME'. + "${FFF_KEY_GO_HOME:=~}") + open ~ + ;; + + # Go to trash. + "${FFF_KEY_GO_TRASH:=t}") + get_os + open "$FFF_TRASH" + ;; + + # Go to previous dir. + "${FFF_KEY_PREVIOUS:=-}") + open "$OLDPWD" + ;; + + # Directory favourites. + [1-9]) + favourite="FFF_FAV${1}" + favourite="${!favourite}" + + [[ $favourite ]] && + open "$favourite" + ;; + + # Quit and store current directory in a file for CD on exit. + # Don't allow user to redefine 'q' so a bad keybinding doesn't + # remove the option to quit. + q) + : "${FFF_CD_FILE:=${XDG_CACHE_HOME:=${HOME}/.cache}/fff/.fff_d}" + + [[ -w $FFF_CD_FILE ]] && + rm "$FFF_CD_FILE" + + [[ ${FFF_CD_ON_EXIT:=1} == 1 ]] && + printf '%s\n' "$PWD" > "$FFF_CD_FILE" + + exit + ;; + esac +} + +main() { + # Handle a directory as the first argument. + # 'cd' is a cheap way of finding the full path to a directory. + # It updates the '$PWD' variable on successful execution. + # It handles relative paths as well as '../../../'. + # + # '||:': Do nothing if 'cd' fails. We don't care. + cd "${2:-$1}" &>/dev/null ||: + + [[ $1 == -v ]] && { + printf '%s\n' "fff 2.2" + exit + } + + [[ $1 == -h ]] && { + man fff + exit + } + + # Store file name in a file on open instead of using 'FFF_OPENER'. + # Used in 'fff.vim'. + [[ $1 == -p ]] && + file_picker=1 + + # bash 5 and some versions of bash 4 don't allow SIGWINCH to interrupt + # a 'read' command and instead wait for it to complete. In this case it + # causes the window to not redraw on resize until the user has pressed + # a key (causing the read to finish). This sets a read timeout on the + # affected versions of bash. + # NOTE: This shouldn't affect idle performance as the loop doesn't do + # anything until a key is pressed. + # SEE: https://github.com/dylanaraps/fff/issues/48 + ((BASH_VERSINFO[0] > 3)) && + read_flags=(-t 0.05) + + ((${FFF_LS_COLORS:=1} == 1)) && + get_ls_colors + + # Create the trash and cache directory if they don't exist. + mkdir -p "${XDG_CACHE_HOME:=${HOME}/.cache}/fff" \ + "${FFF_TRASH:=${XDG_DATA_HOME:=${HOME}/.local/share}/fff/trash}" + + # 'nocaseglob': Glob case insensitively (Used for case insensitive search). + # 'nullglob': Don't expand non-matching globs to themselves. + shopt -s nocaseglob nullglob + + # Trap the exit signal (we need to reset the terminal to a useable state.) + trap 'reset_terminal' EXIT + + # Trap the window resize signal (handle window resize events). + trap 'get_term_size; redraw' WINCH + + get_os + get_term_size + get_w3m_path + setup_options + setup_terminal + redraw full + + # Vintage infinite loop. + for ((;;)); { + read "${read_flags[@]}" -srn 1 && key "$REPLY" + + # Exit if there is no longer a terminal attached. + [[ -t 1 ]] || exit 1 + } +} + +main "$@" + diff --git a/bin/gitlocal b/bin/gitlocal new file mode 100755 index 0000000..2b87303 --- /dev/null +++ b/bin/gitlocal @@ -0,0 +1,34 @@ +#!/bin/bash + +set -eu + +remote="git.pi" + + +cmd=${1:-""} + +if [ "$cmd" == "init" ]; then + name="$2" + + if [ ! -d "$name" ]; then + mkdir $name + fi; + + cd $name + ssh git@git.pi "./create-repo.sh $name" + + if [ ! -d ".git" ]; then + git init + fi; + git remote add local "git@$remote:$name.git" +elif [ "$cmd" == "clone" ]; then + name="$2" + git clone "git@$remote:$name.git" $name +else + echo "usage: gitlocal (init|clone) repository + +remote: $remote + +init: initialize repository on the remote server, then create a local folder linked to the remote +clone: clone a git repository from the remote"; +fi; diff --git a/bin/nix-logo b/bin/nix-logo new file mode 100644 index 0000000..e57f903 --- /dev/null +++ b/bin/nix-logo @@ -0,0 +1,31 @@ +#!/usr/bin/env fish + +set_color cyan +echo -e " sMMd\ \MMMN\ /hMMs \n\ + \MMMm\ \NMMMY.mMMM/ \n\ + \MMMN\ \mMMMNMMM/ \n\ + /dmmmmNMMMMmmmmmhdMMMMN/ ¸¸ \n\ + /MMMMMMMMMMMMMMMMMdhMMMd\ /NM/ \n\ + ``````-hddd/````````\MMMm\ /MMMm/ \n\ + /NMMM/ \NMMdsMMMd/ \n\ +,,,,,,,,/MMMM/ \NddMMMNo\,,,,\n\ +hMMMMMMMMMMm| |mMMMMMMMMMMh\n\ +`````oNMMMdhN\ /NMMM/´´´´´´´´\n\ + /dMMMyhMMM\ /MMMN/ \n\ + /mMMM/ \mMMMo,,,,,,,,/dddd-,,,,,¸ \n\ + \MNM/ \dMMMhdMMMMMMMMMMMMMMMMM/ \n\ + ´´ /NMMMMdhmmmmmMMMMNmmmmd/ \n\ + /NMMN:MMMm\ \NMMM\ \n\ + /MMMm/\MMMN\ \mMMM\ \n\ + sMMd/ \NMMM\ \dMMs " + + + +# +# \#\ \#\/#/ +# ############ +# /#/ \#\/#/ +###### ###### +#/#/\#\ /#/ +# ############# +# /#/\#\ \#\ diff --git a/bin/notes b/bin/notes new file mode 100755 index 0000000..e5958df --- /dev/null +++ b/bin/notes @@ -0,0 +1,110 @@ +#!/usr/bin/env fish + +# get file name from path +function fname + string replace -r "^"(dirname "$argv[1]")/ "" "$argv[1]" +end + + +# convert a note name or otherwise stuff to a notes path +function n_path + if string match -qr "^"(realpath ~/notes) "$argv[1]" + echo $argv[1] + end + echo (realpath ~/notes)/(string replace -ar "\s" "_" "$argv[1]") +end + +# ensure .md ending +function ensure_md + if test (count $argv) -eq 0 -a -t 0 + read inp + else + set inp "$argv[1]" + + end + + if string match -qr "\.md\$" "$inp" + echo "$inp" + else + echo "$inp.md" + end +end + + +# edit a note, arg1 = note name +function note_edit + eval $EDITOR (n_path "$argv[1]" | ensure_md) +end + +# create a new note +# agr1 = note name (path) +# arg2 = (opt) note content +function note_new + set path (n_path "$argv[1]" | ensure_md) + + if test -f "$path" + echo "note at $path already exists" + exit 1 + end + + # create path for note + mkdir -p (dirname "$path") + + echo -e "# "(fname "$argv[1]")"\n\n$argv[2]" > $path + + note_edit "$path" +end + +# show a note +# arg1 = path to note (or folder) +# arg2 = delimiter (default=", " +function note_search + set root (realpath ~/notes)/ + set results + + set delim ", " + test -n "$argv[2]"; and set delim "$argv[2]" + + for f in (rg -l "$argv[1]" ~/notes) + set f (string replace "$root" "" "$f") + set results "$f" $results + end + + echo -e (string join "$delim" $results) +end + +# print the contents of a note +# arg1 = desired note path +function note_print + set path (n_path "$argv[1]" | ensure_md) + if test ! -f (n_path "$path") + echo "note at $path is not a file!" + exit 1 + end + + cat "$path" +end + + + +# main +if test "$argv[1]" = "create" + note_new $argv[2..-1] +else if test "$argv[1]" = "edit" + note_edit $argv[2..-1] +else if test "$argv[1]" = "find" -o "$argv[1]" = "search" + note_search $argv[2..-1] +else if test "$argv[1]" = "git" + eval git -C ~/notes/ $argv[2..-1] +else if test "$argv[1]" = "print" -o "$argv[1]" = "show" + note_print $argv[2..-1] +else if test "$argv[1]" = "list" -o "$argv[1]" = "tree" + tree ~/notes/ +else + echo "Unknown argument: $argv[1]" +end + + + + + diff --git a/bin/passw b/bin/passw new file mode 100755 index 0000000..3b71aea --- /dev/null +++ b/bin/passw @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +# grab parameters, trim whitespaces +length="${*// }"; + +# look for easy mode "-e" +if [[ "$length" =~ ^-e$ ]]; then + passw=$(cat /dev/urandom | tr -cd 'a-z0-9' | head -c 32); + echo $passw | tr -d '\n' | xclip -selection c; + echo $passw + exit 0 +elif [[ "$length" =~ ^-e=([0-9]+)$ ]]; then + # get length from regex + len=${BASH_REMATCH[1]}; + passw=$(cat /dev/urandom | tr -cd 'a-z0-9' | head -c "$len"); + echo $passw | tr -d '\n' | xclip -selection c; + echo $passw + exit 0 +# look for -b=bytes +elif [[ "$length" =~ ^-b=([0-9]+)$ ]]; then + # set bytes + bytes=${BASH_REMATCH[1]}; + # set length + let length=4*bytes/3+1; + # instead of ceiling the function, we just floor it and add 1, because the output length was specified in bytes +else + if [[ -z "$length" ]]; then + # if no parameters were given, the default is used + length=32 + bytes=24 + else + if ! [[ "$length" =~ ^[0-9]+$ ]]; then + echo -e "\e[91mError: '$length' is not a number!\e[0m"; + exit 100; + fi + + # calculate the bytes from the length + let bytes=30*length/4; + # ceil the result using python + + bytes=$(python -c "from math import ceil; print ceil($bytes/10.0)" | tr -d '.0'); + fi +fi + +# generate the password +password=$(dd if=/dev/urandom bs=1 count="$bytes" 2>/dev/null | base64); + +# idk why but they keep adding a newline after every 76th character, compensate for that! +let length=length+length/77; + +# cut it and echo it +echo "${password:0:$length}" | tr -d '\n'; + +# we removed the newlines from the middle of the password adn from the end, add the one at the end back +echo ""; + +# copy the password to clipboard +echo "${password:0:$length}" | tr -d '\n' | xclip -selection c; + +exit 0; diff --git a/bin/status-bar b/bin/status-bar new file mode 100755 index 0000000..2f30064 --- /dev/null +++ b/bin/status-bar @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# This script is a simple wrapper which prefixes each i3status line with custom +# information. It is a python reimplementation of: +# http://code.stapelberg.de/git/i3status/tree/contrib/wrapper.pl +# +# To use it, ensure your ~/.i3status.conf contains this line: +# output_format = "i3bar" +# in the 'general' section. +# Then, in your ~/.i3/config, use: +# status_command i3status | ~/i3status/contrib/wrapper.py +# In the 'bar' section. +# +# In its current version it will display the cpu frequency governor, but you +# are free to change it to display whatever you like, see the comment in the +# source code below. +# +# © 2012 Valentin Haenel +# +# This program is free software. It comes without any warranty, to the extent +# permitted by applicable law. You can redistribute it and/or modify it under +# the terms of the Do What The Fuck You Want To Public License (WTFPL), Version +# 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more +# details. + +import sys +import json +from os import listdir +from os.path import isfile, join + +def get_inbox_items(): + path = "/home/anton/inbox" + files = listdir(path) + if not files: + return bar_entry('∅', 'inbox', '#00FF00') + files.sort() + return bar_entry("inbox: " + ", ".join(files), 'inbox', '#FF0000') + + +def bar_entry(content, name, color = '#000000'): + return {'full_text' : content, 'name' : name, 'color': color} + +def print_line(message): + """ Non-buffered printing to stdout. """ + sys.stdout.write(message + '\n') + sys.stdout.flush() + +def read_line(): + """ Interrupted respecting reader for stdin. """ + # try reading a line, removing any extra whitespace + try: + line = sys.stdin.readline().strip() + # i3status sends EOF, or an empty line + if not line: + sys.exit(3) + return line + # exit on ctrl-c + except KeyboardInterrupt: + sys.exit() + +if __name__ == '__main__': + # Skip the first line which contains the version header. + print_line(read_line()) + + # The second line contains the start of the infinite array. + print_line(read_line()) + + while True: + line, prefix = read_line(), '' + # ignore comma at start of lines + if line.startswith(','): + line, prefix = line[1:], ',' + + j = json.loads(line) + # insert information into the start of the json, but could be anywhere + # CHANGE THIS LINE TO INSERT SOMETHING ELSE + j.insert(0, get_inbox_items()) + # and echo back new encoded json + print_line(prefix+json.dumps(j)) + diff --git a/fish/config.fish b/fish/config.fish new file mode 100644 index 0000000..404c04a --- /dev/null +++ b/fish/config.fish @@ -0,0 +1,23 @@ +alias wificonnect='nmcli connection up' +alias nix-shell='nix-shell --command fish' + +set PATH ~/.bin $PATH + +if test "$TERMINAL" = 'termite' + set TERM xterm-color +end + +function on_exit --on-event fish_exit + if test (status -f) = 'Standard input'; + set byebyes "bravo six, going dark" "bye bye" "ight, imma head out" "see ya!" "I'LL BE BACK" "my job here is done" + echo $byebyes[(random 1 (count $byebyes))] + end +end + +function random_iasip + set folge (find "/home/anton/movies/IASIP S1-10/" -iname "*.mkv" | shuf -n 1) + env VLC_VERBOSE=0 vlc "$folge" 2> /dev/null +end + + + diff --git a/fish/fish_variables b/fish/fish_variables new file mode 100644 index 0000000..39787da --- /dev/null +++ b/fish/fish_variables @@ -0,0 +1,31 @@ +# This file contains fish universal variable definitions. +# VERSION: 3.0 +SETUVAR __fish_init_2_39_8:\x1d +SETUVAR __fish_init_2_3_0:\x1d +SETUVAR fish_color_autosuggestion:555\x1ebrblack +SETUVAR fish_color_cancel:\x2dr +SETUVAR fish_color_command:\x2d\x2dbold +SETUVAR fish_color_comment:red +SETUVAR fish_color_cwd:green +SETUVAR fish_color_cwd_root:red +SETUVAR fish_color_end:brmagenta +SETUVAR fish_color_error:brred +SETUVAR fish_color_escape:bryellow\x1e\x2d\x2dbold +SETUVAR fish_color_history_current:\x2d\x2dbold +SETUVAR fish_color_host:normal +SETUVAR fish_color_match:\x2d\x2dbackground\x3dbrblue +SETUVAR fish_color_normal:normal +SETUVAR fish_color_operator:bryellow +SETUVAR fish_color_param:cyan +SETUVAR fish_color_quote:yellow +SETUVAR fish_color_redirection:brblue +SETUVAR fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_user:brgreen +SETUVAR fish_color_valid_path:\x2d\x2dunderline +SETUVAR fish_greeting:Welcome\x20to\x20fish\x2c\x20the\x20friendly\x20interactive\x20shell +SETUVAR fish_key_bindings:fish_default_key_bindings +SETUVAR fish_pager_color_completion:\x1d +SETUVAR fish_pager_color_description:B3A06D\x1eyellow +SETUVAR fish_pager_color_prefix:white\x1e\x2d\x2dbold\x1e\x2d\x2dunderline +SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan diff --git a/fish/fishd.hostname b/fish/fishd.hostname new file mode 100644 index 0000000..93eb0b8 --- /dev/null +++ b/fish/fishd.hostname @@ -0,0 +1,31 @@ +# This file is automatically generated by the fish. +# Do NOT edit it directly, your changes will be overwritten. +SET __fish_init_2_39_8:\x1d +SET __fish_init_2_3_0:\x1d +SET fish_color_autosuggestion:555\x1ebrblack +SET fish_color_cancel:\x2dr +SET fish_color_command:\x2d\x2dbold +SET fish_color_comment:red +SET fish_color_cwd:green +SET fish_color_cwd_root:red +SET fish_color_end:brmagenta +SET fish_color_error:brred +SET fish_color_escape:bryellow\x1e\x2d\x2dbold +SET fish_color_history_current:\x2d\x2dbold +SET fish_color_host:normal +SET fish_color_match:\x2d\x2dbackground\x3dbrblue +SET fish_color_normal:normal +SET fish_color_operator:bryellow +SET fish_color_param:cyan +SET fish_color_quote:yellow +SET fish_color_redirection:brblue +SET fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack +SET fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack +SET fish_color_user:brgreen +SET fish_color_valid_path:\x2d\x2dunderline +SET fish_greeting:Welcome\x20to\x20fish\x2c\x20the\x20friendly\x20interactive\x20shell +SET fish_key_bindings:fish_default_key_bindings +SET fish_pager_color_completion:\x1d +SET fish_pager_color_description:B3A06D\x1eyellow +SET fish_pager_color_prefix:white\x1e\x2d\x2dbold\x1e\x2d\x2dunderline +SET fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan diff --git a/fish/functions/atril.fish b/fish/functions/atril.fish new file mode 100644 index 0000000..4beead2 --- /dev/null +++ b/fish/functions/atril.fish @@ -0,0 +1,9 @@ +function atril --description "the better atril" + echo -ne "opening " + set_color -i cyan + echo -ne "$argv" + set_color normal + echo " in atril..." + command atril $argv & disown +end + diff --git a/fish/functions/bayern-login.fish b/fish/functions/bayern-login.fish new file mode 100644 index 0000000..eb51b75 --- /dev/null +++ b/fish/functions/bayern-login.fish @@ -0,0 +1,18 @@ +# Defined in /tmp/fish.ZxMSyI/bayern-login.fish @ line 2 +function bayern-login + wificonnect @BayernWLAN + set root /home/anton/projects/bavaria-wifi + + set_color -o green; echo -e "CONNECTED"; set_color normal + sleep 2 + bw-check + #set fname all.min-(date +%Y-%m-%d-%H-%M-%S).js + #set js (curl https://hotspot.vodafone.de/bayern/dist/js/all.min.js) + #set sha (echo -n "$js" | sha1sum | string split " ")[1] + + #if ! cat $root/shasums | grep $sha + # echo "$js" > $root/scripts/$fname + # echo "Found new script! sha: $sha. Saved in $root/scripts/$fname" + # echo "$sha" >> $root/shasums + #end +end diff --git a/fish/functions/bw-check.fish b/fish/functions/bw-check.fish new file mode 100644 index 0000000..687dd72 --- /dev/null +++ b/fish/functions/bw-check.fish @@ -0,0 +1,15 @@ +# Defined in /tmp/fish.xZCDu4/bw-check.fish @ line 2 +function bw-check + set root /home/anton/projects/bavaria-wifi + set fname all.min-(date +%Y-%m-%d-%H-%M-%S).js + set js (curl -s https://hotspot.vodafone.de/bayern/dist/js/all.min.js) + set sha (echo -n "$js" | sha1sum | string split " ")[1] + + if ! cat $root/shasums | grep $sha + echo "$js" > $root/scripts/$fname + echo -e "Found new script! sha: $sha.\nSaved in $root/scripts/$fname" + echo "$sha" (date +%Y-%m-%d-%H-%M-%S) >> $root/shasums + else +echo "nothing new" +end +end diff --git a/fish/functions/code-py.fish b/fish/functions/code-py.fish new file mode 100644 index 0000000..03e711a --- /dev/null +++ b/fish/functions/code-py.fish @@ -0,0 +1,3 @@ +function code-py + nix-shell -p python37Packages.pylint --run "code $argv" +end diff --git a/fish/functions/dgc-env.fish b/fish/functions/dgc-env.fish new file mode 100644 index 0000000..e6adcf7 --- /dev/null +++ b/fish/functions/dgc-env.fish @@ -0,0 +1,4 @@ +function dgc-env + set p3p python37Packages +nix-shell -p $p3p.requests $p3p.lxml $p3p.beautifulsoup4 $p3p.clint +end diff --git a/fish/functions/fish_greeting.fish b/fish/functions/fish_greeting.fish new file mode 100644 index 0000000..2adf97a --- /dev/null +++ b/fish/functions/fish_greeting.fish @@ -0,0 +1,19 @@ +function fish_greeting + if test "$TERM_PROGRAM" = vscode + return + end + + set greetings "Hello there" (echo -ne "Aye aye, "; set_color -o; echo -ne "captain"; set_color normal) \ + "Welcome back, Commander Shepard" "Waiting for orders!" + + set greet $greetings[(random 1 (count $greetings))] + + echo -ne "\n\t"$greet"\n\n" + + if test (count (ls -A ~/inbox)) -ne 0; + set_color red + echo -e "\tInbox not empty!" + set_color normal + ls -1 --quoting-style=literal inbox/ | string join ", " + end +end diff --git a/fish/functions/fish_prompt.fish b/fish/functions/fish_prompt.fish new file mode 100644 index 0000000..d92973c --- /dev/null +++ b/fish/functions/fish_prompt.fish @@ -0,0 +1,37 @@ +# Defined in /home/anton/.config/fish/functions/fish_prompt.fish @ line 1 +function fish_prompt + set -l git_branch (git branch ^/dev/null | sed -n '/\* /s///p') + + if test -n "$git_branch" -a (pwd) != /home/anton + set git_branch " [$git_branch]" + else + set git_branch "" + end + + if test -n "$IN_NIX_SHELL" + set_color cyan + echo -n "nix " + set_color normal + end + + # set_color cyan + echo -n (whoami) + set_color normal + echo -n '@' + # set_color bryellow + echo -n (hostname) + + if status is-interactive-job-control; and test (jobs | wc -l) -gt 0 + set_color cyan + echo -n " #"(jobs | wc -l) + end + + set_color yellow + echo -n "$git_branch" + + set_color green + echo -n ' '(prompt_pwd) + + set_color normal + echo ' > ' +end diff --git a/fish/functions/inbox.fish b/fish/functions/inbox.fish new file mode 100644 index 0000000..96a91e4 --- /dev/null +++ b/fish/functions/inbox.fish @@ -0,0 +1,21 @@ +function inbox -d "manipulate your inbox" + if test -z "$argv" + ls -1 --quoting-style=literal ~/inbox/ | string join ", " + return + end + + if test "$argv" = "--clear" + rm -r ~/inbox/* + return + end + + if echo "$argv" | grep -q " -mv " + set move_flag true + end + + if test -f "$argv[1]" -o -d "$argv[1]" + cp -r "$argv[1]" ~/inbox/ + else + echo -e (string join "\n" $argv[2..-1])"\n" > ~/inbox/$argv[1] + end +end diff --git a/fish/functions/ll.fish b/fish/functions/ll.fish new file mode 100644 index 0000000..d1072a4 --- /dev/null +++ b/fish/functions/ll.fish @@ -0,0 +1,4 @@ +# Defined in - @ line 1 +function ll --description 'alias ll=ls -AlFh' + ls -AlFh $argv; +end diff --git a/fish/functions/mount-vc.fish b/fish/functions/mount-vc.fish new file mode 100644 index 0000000..60b53f8 --- /dev/null +++ b/fish/functions/mount-vc.fish @@ -0,0 +1,4 @@ +# Defined in /tmp/fish.dwCY0N/mount-vc.fish @ line 2 +function mount-vc --argument device key_name target -d Mount a veracrypt container with a keyfile stored in /home/anton/.keys + nix-shell -p veracrypt --run "sudo veracrypt -k /home/anton/.keys/$argv[2] -p \"\" $argv[1] $argv[3]" +end diff --git a/fish/functions/pythonEnv.fish b/fish/functions/pythonEnv.fish new file mode 100644 index 0000000..a491b81 --- /dev/null +++ b/fish/functions/pythonEnv.fish @@ -0,0 +1,11 @@ +function pythonEnv --description 'start a nix-shell with the given python packages' --argument pythonVersion + if set -q argv[2] + set argv $argv[2..-1] + end + + for el in $argv + set ppkgs $ppkgs "python"$pythonVersion"Packages.$el" + end + + nix-shell -p $ppkgs +end diff --git a/fish/functions/telegram.fish b/fish/functions/telegram.fish new file mode 100644 index 0000000..1b2c77d --- /dev/null +++ b/fish/functions/telegram.fish @@ -0,0 +1,3 @@ +function telegram + nix-shell -p tdesktop --run "telegram-desktop >/dev/null 2>&1 & disown" +end diff --git a/fish/functions/vi.fish b/fish/functions/vi.fish new file mode 100644 index 0000000..8714e1e --- /dev/null +++ b/fish/functions/vi.fish @@ -0,0 +1,4 @@ +# Defined in - @ line 1 +function vi --description 'alias vi nvim' + nvim $argv; +end diff --git a/i3/config b/i3/config new file mode 100644 index 0000000..28f6eb0 --- /dev/null +++ b/i3/config @@ -0,0 +1,218 @@ +# This file has been auto-generated by i3-config-wizard(1). +# It will not be overwritten, so edit it as you like. +# +# Should you change your keyboard layout some time, delete +# this file and re-run i3-config-wizard(1). +# + +# i3 config file (v4) +# +# Please see https://i3wm.org/docs/userguide.html for a complete reference! + +set $mod Mod4 + +# Font for window titles. Will also be used by the bar unless a different font +# is used in the bar {} block below. +# font pango:monospace 8 + +# remove window bar heading: +for_window [class="^.*"] border pixel 2 + +smart_borders on +smart_gaps on + +gaps inner 8 + + +# This font is widely installed, provides lots of unicode glyphs, right-to-left +# text rendering and scalability on retina/hidpi displays (thanks to pango). +font pango:DejaVu Sans Mono 8 + +# The combination of xss-lock, nm-applet and pactl is a popular choice, so +# they are included here as an example. Modify as you see fit. + +# xss-lock grabs a logind suspend inhibit lock and will use i3lock to lock the +# screen before suspend. Use loginctl lock-session to lock your screen. +exec --no-startup-id xss-lock --transfer-sleep-lock -- i3lock --nofork + +# NetworkManager is the most popular way to manage wireless networks on Linux, +# and nm-applet is a desktop environment-independent system tray GUI for it. +exec --no-startup-id nm-applet + + + +# Use pactl to adjust volume in PulseAudio. +set $refresh_i3status killall -SIGUSR1 i3status +bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +10% && $refresh_i3status +bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ -10% && $refresh_i3status +bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute @DEFAULT_SINK@ toggle && $refresh_i3status +bindsym XF86AudioMicMute exec --no-startup-id pactl set-source-mute @DEFAULT_SOURCE@ toggle && $refresh_i3status + + +# Brightness control +bindsym XF86KbdBrightnessUp exec --no-startup-id /home/anton/.bin/brihgtness +15 +bindsym XF86KbdBrightnessDown exec --no-startup-id /home/anton/.bin/brightness -15 + + +# Use Mouse+$mod to drag floating windows to their wanted position +floating_modifier $mod + +# start a terminal +bindsym $mod+Return exec i3-sensible-terminal + +# kill focused window +bindsym $mod+Shift+q kill + +# start dmenu (a program launcher) +bindsym $mod+d exec dmenu_run +# There also is the (new) i3-dmenu-desktop which only displays applications +# shipping a .desktop file. It is a wrapper around dmenu, so you need that +# installed. +# bindsym $mod+d exec --no-startup-id i3-dmenu-desktop + +# change focus +bindsym $mod+j focus left +bindsym $mod+k focus down +bindsym $mod+l focus up +bindsym $mod+odiaeresis focus right + +# alternatively, you can use the cursor keys: +bindsym $mod+Left focus left +bindsym $mod+Down focus down +bindsym $mod+Up focus up +bindsym $mod+Right focus right + +# move focused window +bindsym $mod+Shift+j move left +bindsym $mod+Shift+k move down +bindsym $mod+Shift+l move up +bindsym $mod+Shift+odiaeresis move right + +# alternatively, you can use the cursor keys: +bindsym $mod+Shift+Left move left +bindsym $mod+Shift+Down move down +bindsym $mod+Shift+Up move up +bindsym $mod+Shift+Right move right + +# split in horizontal orientation +bindsym $mod+h split h + +# split in vertical orientation +bindsym $mod+v split v + +# enter fullscreen mode for the focused container +bindsym $mod+f fullscreen toggle + +# change container layout (stacked, tabbed, toggle split) +bindsym $mod+s layout stacking +bindsym $mod+w layout tabbed +bindsym $mod+e layout toggle split + +# toggle tiling / floating +bindsym $mod+Shift+space floating toggle + +# change focus between tiling / floating windows +bindsym $mod+space focus mode_toggle + +# focus the parent container +bindsym $mod+a focus parent + +# focus the child container +#bindsym $mod+d focus child + +# Define names for default workspaces for which we configure key bindings later on. +# We use variables to avoid repeating the names in multiple places. +set $ws1 "1" +set $ws2 "2" +set $ws3 "3" +set $ws4 "4" +set $ws5 "5" +set $ws6 "6" +set $ws7 "7" +set $ws8 "8" +set $ws9 "9" +set $ws10 "10" + +# switch to workspace +bindsym $mod+1 workspace number $ws1 +bindsym $mod+2 workspace number $ws2 +bindsym $mod+3 workspace number $ws3 +bindsym $mod+4 workspace number $ws4 +bindsym $mod+5 workspace number $ws5 +bindsym $mod+6 workspace number $ws6 +bindsym $mod+7 workspace number $ws7 +bindsym $mod+8 workspace number $ws8 +bindsym $mod+9 workspace number $ws9 +bindsym $mod+0 workspace number $ws10 + +# move focused container to workspace +bindsym $mod+Shift+1 move container to workspace number $ws1 +bindsym $mod+Shift+2 move container to workspace number $ws2 +bindsym $mod+Shift+3 move container to workspace number $ws3 +bindsym $mod+Shift+4 move container to workspace number $ws4 +bindsym $mod+Shift+5 move container to workspace number $ws5 +bindsym $mod+Shift+6 move container to workspace number $ws6 +bindsym $mod+Shift+7 move container to workspace number $ws7 +bindsym $mod+Shift+8 move container to workspace number $ws8 +bindsym $mod+Shift+9 move container to workspace number $ws9 +bindsym $mod+Shift+0 move container to workspace number $ws10 + +# reload the configuration file +bindsym $mod+Shift+c reload +# restart i3 inplace (preserves your layout/session, can be used to upgrade i3) +bindsym $mod+Shift+r restart +# exit i3 (logs you out of your X session) +bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -B 'Yes, exit i3' 'i3-msg exit'" + +# resize window (you can also use the mouse for that) +mode "resize" { + # These bindings trigger as soon as you enter the resize mode + + # Pressing left will shrink the window’s width. + # Pressing right will grow the window’s width. + # Pressing up will shrink the window’s height. + # Pressing down will grow the window’s height. + bindsym j resize shrink width 10 px or 10 ppt + bindsym k resize grow height 10 px or 10 ppt + bindsym l resize shrink height 10 px or 10 ppt + bindsym odiaeresis resize grow width 10 px or 10 ppt + + # same bindings, but for the arrow keys + bindsym Left resize shrink width 10 px or 10 ppt + bindsym Down resize grow height 10 px or 10 ppt + bindsym Up resize shrink height 10 px or 10 ppt + bindsym Right resize grow width 10 px or 10 ppt + + # back to normal: Enter or Escape or $mod+r + bindsym Return mode "default" + bindsym Escape mode "default" + bindsym $mod+r mode "default" +} + +bindsym $mod+r mode "resize" + +# Start i3bar to display a workspace bar (plus the system information i3status +# finds out, if available) +bar { + status_command i3status | ~/.bin/status-bar +} + + +set $mode_sys System (l)ock (h)ibernate log(o)ut (Shift+s)hutdown (r)eboot + +mode "$mode_sys" { + bindsym l exec --no-startup-id i3lock -i pics/nix-blue-small.png, mode "default" + bindsym r exec --no-startup-id reboot, mode "default" + bindsym o exec --no-startup-id i3-msg exit, mode "default" + bindsym h exec --no-startup-id i3lock -i Pictures/nix-dark-small.png && systemctl hibernate, mode "default" + bindsym Shift+s exec --no-startup-id shutdown now, mode "default" + + bindsym Return mode "default" + bindsym Escape mode "default" +} + +bindsym $mod+End mode "$mode_sys" + + +# screenshots +bindsym $mod+Print exec flameshot gui diff --git a/i3status/config b/i3status/config new file mode 100644 index 0000000..7008c12 --- /dev/null +++ b/i3status/config @@ -0,0 +1,53 @@ +# i3status configuration file. +# see "man i3status" for documentation. +# It is important that this file is edited as UTF-8. +# The following line should contain a sharp s: +# ß +# If the above line is not correctly displayed, fix your editor first! + +general { + output_format = i3bar + colors = true + interval = 1 +} + +#order += "ipv6" +order += "wireless _first_" +order += "ethernet _first_" +order += "battery all" +order += "disk /" +order += "load" +order += "memory" +order += "tztime local" + +wireless _first_ { + format_up = "W: (%quality at %essid) %ip" + format_down = "W: -" +} + +ethernet _first_ { + format_up = "E: %ip (%speed)" + format_down = "E: -" +} + +battery all { + format = "%status %percentage (%remaining at %consumption)" +} + +disk "/" { + format = "%avail" +} + +load { + format = "%1min" +} + +memory { + format = "%used ~ %available" + threshold_degraded = "1G" + format_degraded = "MEMORY < %available" +} + +tztime local { + format = "%Y-%m-%d %H:%M:%S" +} diff --git a/nixos/configuration.nix b/nixos/configuration.nix new file mode 100644 index 0000000..1734bae --- /dev/null +++ b/nixos/configuration.nix @@ -0,0 +1,189 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ config, pkgs, ... }: + +{ + imports = + [ # Include the results of the hardware scan. + ./hardware-configuration.nix + ./lenovo-configuration.nix + ]; + + # Use the systemd-boot EFI boot loader. + + fileSystems.boot.device = "/dev/sda1"; + fileSystems.boot.mountPoint = "/boot"; + + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + boot.loader.efi.efiSysMountPoint = "/boot/efi"; + boot.loader.grub = { + enable = true; + device = "nodev"; + version = 2; + efiSupport = true; + enableCryptodisk = true; + useOSProber = true; + splashImage = "/home/anton/pics/nix-dark-small-red.png"; + }; + boot.initrd.luks.devices = [ + { + name = "root"; + device = "/dev/disk/by-uuid/02799bea-98ce-4a38-8772-886303170455"; + preLVM = true; + allowDiscards = true; + } + ]; + boot.kernelParams = [ "noapic" ]; + boot.tmpOnTmpfs = true; + + networking.hostName = "hostname"; # Define your hostname. + networking.networkmanager = { + wifi.macAddress = "random"; + wifi.scanRandMacAddress = true; + + # ethernet.macAddress = "random"; + enable = true; + }; + networking.nameservers = [ + "194.150.168.168" + "212.82.226.212" + "1.1.1.1" + ]; + + + # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. + + # The global useDHCP flag is deprecated, therefore explicitly set to false here. + # Per-interface useDHCP will be mandatory in the future, so this generated config + # replicates the default behaviour + # networking.useDHCP = false; + networking.interfaces.enp2s0.useDHCP = true; + networking.interfaces.wlp4s0.useDHCP = true; + + # Configure network proxy if necessary + # networking.proxy.default = "http://user:password@proxy:port/"; + # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; + + # Select internationalisation properties. + i18n = { + consoleFont = "Lat2-Terminus16"; + consoleKeyMap = "de"; + defaultLocale = "en_US.UTF-8"; + }; + + # Set your time zone. + time.timeZone = "Europe/Amsterdam"; + + # List packages installed in system profile. To search, run: + # $ nix search wget + nixpkgs.config.allowUnfree = true; + + environment.systemPackages = with pkgs; [ + wget vim neovim manpages termite pass coreutils + unzip gzip htop nload firefox ghc vlc gcc python3 + fish git file ripgrep os-prober vscode thunderbird + mate.atril xorg.xbacklight gnupg lxqt.pavucontrol-qt + inkscape xorg.xrandr redshift tree + exfat-utils fuse_exfat flameshot ntfs3g + (texlive.combine { + inherit(texlive) scheme-full; + }) + ]; + environment.variables = { + EDITOR = "nvim"; + TERMINAL = [ "termite" ]; + }; + + # Some programs need SUID wrappers, can be configured further or are + # started in user sessions. + # programs.mtr.enable = true; + # programs.gnupg.agent = { enable = true; enableSSHSupport = true; }; + + # List services that you want to enable: + + # Enable the OpenSSH daemon. + # services.openssh.enable = true; + + services = { + #redshift = { + # enable = true; + # temperature.night = 2300; + # extraOptions = [ "-l 50.11552:8.68417" ]; + #}; + + xserver = { + enable = true; + layout = "de"; + xkbVariant = "nodeadkeys"; + + windowManager.i3 = { + enable = true; + package = pkgs.i3-gaps; + }; + + windowManager.default = "i3"; + displayManager.lightdm.enable = true; + libinput.enable = true; + desktopManager.xterm.enable = false; + }; + + compton.enable = true; + + timesyncd.servers = [ "0.nixos.pool.ntp.org" ]; + }; + + programs = { + fish.enable = true; + bash.enableCompletion = true; + }; + + location = { + latitude = 50.11552; + longitude = 8.68417; + }; + + # bat state service + # started after xserver is initiated + systemd.user.services.batstate = { + description = "Handles redshift, but flashes the screen red, if the batery level jump below a specific level"; + wantedBy = [ "graphical-session.target" ]; + enable = true; + environment = { BAT_CRITICAL_LEVEL = "8"; BAT_ALARM_TEMP = "1800"; DISPLAY = ":0"; }; + script = "/home/anton/.bin/bat-state"; + path = with pkgs; [ fish redshift xorg.xrandr ]; + }; + + systemd.user.services.flameshot = { + description = "Flameshot screenshot service"; + wantedBy = [ "graphical-session.target" ]; + enable = true; + script = "flameshot"; + path = with pkgs; [ flameshot ]; + }; + + # Open ports in the firewall. + networking.firewall.allowedTCPPortRanges = [ {from= 4000; to= 5000;} ]; + # networking.firewall.allowedUDPPorts = [ ... ]; + # Or disable the firewall altogether. + networking.firewall.enable = true; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.anton = { + isNormalUser = true; + extraGroups = [ "wheel" "networkmanager" "power" "audio" "video" "plugdev" ]; + uid = 1000; + createHome = true; + home = "/home/anton"; + shell = pkgs.fish; + }; + + # This value determines the NixOS release with which your system is to be + # compatible, in order to avoid breaking some software such as database + # servers. You should change this only after NixOS release notes say you + # should. + system.stateVersion = "19.09"; # Did you read the comment? +} + diff --git a/nixos/hardware-configuration.nix b/nixos/hardware-configuration.nix new file mode 100644 index 0000000..2a0b666 --- /dev/null +++ b/nixos/hardware-configuration.nix @@ -0,0 +1,36 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, ... }: + +{ + imports = + [ + ]; + + boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "sd_mod" "sdhci_pci" ]; + boot.initrd.kernelModules = [ "dm-snapshot" ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/212b8703-209b-48b5-81d9-928f4cd440a7"; + fsType = "ext4"; + }; + + fileSystems."/boot" = + { device = "/dev/disk/by-uuid/53ed064a-4da5-477b-84ed-974d9020491d"; + fsType = "ext4"; + }; + + fileSystems."/boot/efi" = + { device = "/dev/disk/by-uuid/6398-D785"; + fsType = "vfat"; + }; + + swapDevices = + [ { device = "/dev/disk/by-uuid/a6578ff4-7451-478b-a938-421c69d1ea1e"; } + ]; + + nix.maxJobs = lib.mkDefault 8; +} diff --git a/nixos/lenovo-configuration.nix b/nixos/lenovo-configuration.nix new file mode 100644 index 0000000..71cef10 --- /dev/null +++ b/nixos/lenovo-configuration.nix @@ -0,0 +1,20 @@ +{ config, pkgs, ... }: + +{ + services = { + # power management + #tlp.enable = true; + + upower.enable = true; + }; + + powerManagement.scsiLinkPolicy = "med_power_with_dipm"; + + # sound + sound.enable = true; + hardware.pulseaudio.enable = true; + + # backlight + hardware.acpilight.enable = true; + +} diff --git a/setup.fish b/setup.fish new file mode 100755 index 0000000..f6feb3b --- /dev/null +++ b/setup.fish @@ -0,0 +1,54 @@ +#!/usr/bin/env fish + +set DOTFILES_REPO (pwd) + +## add thing to dotfiles repository (path or file) +function add_dotfiles + set system "$argv[1]" + set local "$argv[2]" + + if grep -q -e "^$local" system_setup + echo "folder $local already in repo!" + return + end + + if test -d "$system" + cp -r "$system" "$local" + rm -rf "$system" + else if test -f "$system" + cp "$system" "$local" + rm -f "$system" + else + echo "unknown file type at $argv[1]" + return + end + + ln -s "$DOTFILES_REPO"/"$argv[2]" "$argv[1]" + + echo "$argv[2] $argv[1]" >> system_setup +end + +## link dotfiles everywhere +function restore_system + for line in (cat system_setup) + if test -z $line + continue + end + + set line (string split -n " " "$line") + + set local "$line[1]" + set system "$line[2]" + + echo $local → $system + + rm -rf "$system" + ln -s "$DOTFILES_REPO"/"$local" "$system" + end +end + +if test "$argv[1]" = "add" + add_dotfiles $argv[2..-1] +else if test "$argv[1]" = "build" + restore_system $argv[2..-1] +end \ No newline at end of file diff --git a/system_setup b/system_setup new file mode 100644 index 0000000..11cd589 --- /dev/null +++ b/system_setup @@ -0,0 +1,6 @@ +bin /home/anton/.bin +i3 /home/anton/.config/i3 +i3status /home/anton/.config/i3status +termite /home/anton/.config/termite +fish /home/anton/.config/fish +nixos /etc/nixos diff --git a/termite/config b/termite/config new file mode 100644 index 0000000..23b53a9 --- /dev/null +++ b/termite/config @@ -0,0 +1,10 @@ +[options] +audible_bell=1 +allow_bold=1 +bold_is_bright=1 +scrollback_lines=100000 + +[colors] +#background=#181818 +background=rgba(24, 24, 24, 0.8) +