Skip to content

Instantly share code, notes, and snippets.

@erols
Last active March 25, 2021 12:24
Show Gist options
  • Select an option

  • Save erols/54055f41b31fd12198cddb6124319972 to your computer and use it in GitHub Desktop.

Select an option

Save erols/54055f41b31fd12198cddb6124319972 to your computer and use it in GitHub Desktop.

Shell Tips

re-runs the previous command as sudo

!! re-runs last succsessful command
sudo !!

killing and yanking text

ctrl - k kill (cut) to the end of the line

ctrl - y pastes back whatever was just cut

ctrl - u kill to the beginning of the line

ctrl - w kill word

replace tail with less

less +F starts at the end of the file

edit comnmand in editor

ctrl-x-e will put you in your default editor with the cammand ready to edit. Writing and quiting puts the command back in your terminal and executes it

paste the argument of the previous command

alt . will give the argument of the last successful command

unlock your terminal (e.g. broken ssh)

reset

~ . after you lose connection to a remote ssh session

close the shell

ctrl-d

movements in the shell

ctrl-a gets you to the beginning of the line

ctrl-e gets you to the end of the line

ctrl-c to get out of what you are currently typing without executing

alt-f moves you forward to the next word delimeter

alt-b moves you back to the beginning of the word

reload shell

exec {$SHELL}

search history

history shows history

ctrl-r does a reverse search in your history. do ctrl-r, type in your search, keep pressing ctrl-r to keep going back through history

ctrl-g gets you out of the reverse search

File size

ncdu Find files by size, recursively, below the current folder

Create difficult to guess password

mkpasswd -l n n = the number of characters in the password
makepasswd --chars=n n = the number of characters in the password

Nvidia requirements

sudo apt-get install bumblebee bumblebee-nvidia primus linux-headers-generic

in grub - nouveau.modeset=0

Powerline - Ubuntu 18.04

First remove and purge all existing powerline installations. If you installed with pip install --user you will have to delete the folders in $HOME\.local

Install fonts. Either sudo apt install fonts-powerline or follow instructions here: https://powerline.readthedocs.io/en/master/installation/linux.html#fonts-installation

Then pip install sudo pip install powerline-status

For bash support add these lines in .bashrc:

if [ -f /usr/local/lib/python3.6/dist-packages/powerline/bindings/bash/powerline.sh ]; then
    source /usr/local/lib/python3.6/dist-packages/powerline/bindings/bash/powerline.sh
fi

For tmux support add these lines in .tmux.conf:

run-shell "powerline-daemon -q"
source "/usr/local/lib/python3.6/dist-packages/powerline/bindings/tmux/powerline.conf"

For vim support add these lines in .vimrc:

python3 from powerline.vim import setup as powerline_setup
python3 powerline_setup()
python3 del powerline_setup

GIT

push local branch to remote
git push -u origin <local-branch-name>

delete remote branch
$ git push origin --delete <branch_name>

delete local branch
$ git branch -d <branch_name>

Monitor settings - xrandr

get low level settings for desired resolution and refresh rate

$ gtf 2560 1440 30

  # 2560x1440 @ 30.00 Hz (GTF) hsync: 43.95 kHz; pclk: 146.27 MHz
  Modeline "2560x1440_30.00"  146.27  2560 2680 2944 3328  1440 1441 1444 1465  -HSync +Vsync

Copy numbers after Modeline "2560x1440_30.00" to end. Then use copied info to create a new mode

$ xrandr --newmode "MODE_NAME" 146.27 2560 2680 2944 3328 1440 1441 1444 1465 -HSync +Vsync

Add new mode to desired monitor. (The monitor name can be found by simply executing $ xrandr)

$ xrandr --addmode MONITOR_NAME MODE_NAME

Switch to new mode

$ xrandr --output MONITOR_NAME --mode MODE_NAME

poetry doesn't work on ubuntu 20.04

  • If installed, disable pyenv by commenting out pyenv init in .bashrc
  • Start new shell
  • install pip3 sudo apt install python3-pip
  • run pip3 install --upgrade keyrings.alt -> This is the fix
  • Now install poetry curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 -
  • edit first line of .poetry/bin/poetry. Change shebang to reference python3 #!/usr/bin/env python3
  • Now poetry works in the command line
  • Re-enable pyenv
  • Check in Pycharm. Using poetry in Add Interpreter now working

Autostart Desktop Entry

How to autostart a program on logging in to your desktop

Create an .desktop file in $HOME/.config/autostart/

Documentation - https://specifications.freedesktop.org/desktop-entry-spec/latest/

The File can refer directly to an executable or to a bash script. E.g.

[Desktop Entry]
Type=Application
Name=Default Soundcard
Terminal=true
Exec=/home/erols/bin/my_autostart_script.sh
Icon=system-run
X-GNOME-Autostart-enabled=true

Set default soundcard

Simple bash script that sets the default soundcard upon logging into the desktop

#! /bin/sh
pactl set-default-sink alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo
pactl set-default-source alsa_input.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo

How to use pact https://wolfgang-ziegler.com/blog/prevent-changing-of-default-ubuntu-sound-device

First, let's get a list of the available audio output devices (sinks) using the pactl command:

$ pactl list short sinks
1	alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1	module-alsa-card.c	s16le 2ch 44100Hz	IDLE
2	alsa_output.usb-FongLun_AmazonBasics_USB_Conference_Mic_201802-00.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	IDLE
3	alsa_output.pci-0000_02_00.0.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	RUNNING
4	alsa_output.pci-0000_00_1f.3.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	IDLE

Then do the same for the input devices (sources):

$ pactl list short sources
1	alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1.monitor	module-alsa-card.c	s16le 2ch 44100Hz	IDLE
2	alsa_input.usb-Microsoft_Microsoft___LifeCam_HD-5000-02.mono-fallback	module-alsa-card.c	s16le 1ch 44100Hz	IDLE
3	alsa_output.usb-FongLun_AmazonBasics_USB_Conference_Mic_201802-00.analog-stereo.monitor	module-alsa-card.c	s16le 2ch 44100Hz	IDLE
4	alsa_input.usb-FongLun_AmazonBasics_USB_Conference_Mic_201802-00.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	IDLE
5	alsa_output.pci-0000_02_00.0.analog-stereo.monitor	module-alsa-card.c	s16le 2ch 44100Hz	IDLE
6	alsa_output.pci-0000_00_1f.3.analog-stereo.monitor	module-alsa-card.c	s16le 2ch 44100Hz	IDLE

Now, using the set-default-sink and set-default-source options of the pactl command, we can set the default input and output devices. This can either be done using the number or the device name (I recommend working with device names however, since those numbers seem to be changing across reboots).

Example:

$ pactl set-default-source alsa_output.pci-0000_00_1f.3.analog-stereo
$ pactl set-default-sink alsa_output.pci-0000_00_1f.3.analog-stereo

Was suggested to add to .bashrc in the website. This didn't work for me. I created an autostart desktop entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment