You are not logged in.
When you need to know what Wifis are in range and what there signal strength is and you don't want to go through tons of information from iw
(needs su privileges)
#/bin/bash
iw dev <insert device> scan | grep -E 'DS Parameter set|SSID|BSS|signal'
Last edited by Drehstromlampe (2017-01-20 14:54:57)
Offline
[Edit: in response to Alad's dependency thing]
And you might want to make that first one
expac -Q '%n\n%S' -l '\n'
to handle "provides".
Last edited by Raynman (2017-01-20 14:55:02)
Offline
Drehstromlampe, I ditched iw and wireless_tools some time ago when I realized I needed wpa_supplicant regardless, and wpa_supplicant's wpa_cli acheived all the same goals anyways. It's nice to be able to use one tool for *all* wireless networks, instead of having to switch tools when on and open vs secure network. And wpa_cli has a nice clean output by default:
wpa_cli -i <interface> scan && wpa_cli -i <interface> scan_result
I have that aliased for when I'm out and about and some employee behind the cafe bar mumbles the name of their network without specifying anything about punctuation, capitalization, or spaces.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Note that piping within awk is generally slower than piping it's output. I've confirmed that in this case. Also piping outside awk seems far more readable to me.
[Edit: in response to Alad's dependency thing]
And you might want to make that first oneexpac -Q '%n\n%S' -l '\n'
to handle "provides".
I've made some edits. Thanks.
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
Highlight function for bash. Source it from .bashrc or .bash_aliases or wherever you like.
hl() {
# usage: cat file | hl <pattern>
#
# man 1 grep
GREP_COLORS="ms=01;36:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36" egrep --color "^|$1"
}
Offline
Useless Use Of Cat award. ^ Really, just make that an alias for `GREP_COLORS="ms=01;36:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36" egrep --color`
Also, I use ag for that, which is faster than grep and automatically highlights anyway.
Last edited by eschwartz (2017-01-23 00:12:11)
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
Why alias the whole variable? Just set the variable like other environment variables. If you want you can alias grep to `grep --color`.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Maybe it's for special occasions, like birthdays or first dates.
Last edited by Awebb (2017-01-23 00:57:05)
Online
Well, maybe there is some sort of inscrutable reason to prefer that only in this specific invocation should the default colors not be used. The fact that the variable is not already set would imply that yanthor is not using it elsewhere, but what do I know?
(Anyway, exporting an environment variable mildly bloats the environment of all processes, and incurs some sort of miniscule startup penalty, so...)
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
It's two in the morning, but am I correct in the assumption, that changing a single "1" into an "@" might chase the cat away?
Online
Just to show how you can 'customize' git, assuming ~/bin is in your PATH:
# ~/bin/git-commit-and-push
#!/bin/env python
import sys
import subprocess
def main():
message = sys.argv[1]
subprocess.check_call(["git", "commit", "--all",
"--message", message])
subprocess.check_call(["git", "push"])
if __name__ == "__main__":
main()
And then
# in ~/.config/git/config
alias cp = git-commit-and-push
Then use git cp "this is the message" to commit everything and push in one go.
I have a few other git commands written this way in my dotfiles repo
Responsible Coder, Python Fan, Rust enthusiast
Offline
Hey folks, thanks for the replies.
The hl() is result of my effort to use $1 into an alias, which turns out is impossible. I can't recall now, it was long time ago, I want to see all the output, not cutting(grep) any lines, and only mark what i needed to.
Just found about GREP_COLORS minutes before posting here. If one likes - can customize it right there.
$@ will be "expanded" "into" "words". Using $1 like pattern1\|pattern2\|or\ more works better for me.
Cheers!
Offline
Just to show how you can 'customize' git, assuming ~/bin is in your PATH:
# ~/bin/git-commit-and-push #!/bin/env python import sys import subprocess def main(): message = sys.argv[1] subprocess.check_call(["git", "commit", "--all", "--message", message]) subprocess.check_call(["git", "push"]) if __name__ == "__main__": main()
And then
# in ~/.config/git/config alias cp = git-commit-and-push
Then use git cp "this is the message" to commit everything and push in one go.
I have a few other git commands written this way in my dotfiles repo
This is a really bad example, since it is simple enough to be written as a git alias and in any event you just required loading python.
Looking at your other scripts, most of them could really be aliases (git aliases can even invoke the shell if needed).
git-cco appears to essentially do exactly what git natively does, but in python and assuming remotes can only ever be called "origin".
I cannot think why one would want to commit-and-rebase, but -a -v --no-verify seems outside the name of that command and it should still be an alias.
push-all-and-fetch seems to push the master branch to a remote named "all" which is oddly specific, then does an overly-verbose "git remote update", which should never be necessary unless someone else is pushing from elsewhere (and you didn't correctly push all local branches).
fpush duplicates the builtin git error reporting, then encourages useless commit messages. Please just use `git commit "$file" -m "" --allow-empty-message && git push` instead. And maybe skip the automatic pushes.
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
Hey folks, thanks for the replies.
The hl() is result of my effort to use $1 into an alias, which turns out is impossible. I can't recall now, it was long time ago, I want to see all the output, not cutting(grep) any lines, and only mark what i needed to.Just found about GREP_COLORS minutes before posting here. If one likes - can customize it right there.
$@ will be "expanded" "into" "words". Using $1 like pattern1\|pattern2\|or\ more works better for me.
Cheers!
... and aliases can't exclude the space between the expansion and the following parameters, I see what you mean.
BTW, using $1 instead of $@ simply drops the second and later words, the point of using $@ is would be to pass the file to grep and thereby avoid cats.
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
Hi!
this is my first post here , am new to arch linux and i hope i will be welcomed here
i wrote a simple script to organize my files
#!/usr/bin/python
#*******************script for organizing files *********************#
import os
import shutil
import sys
############ public variables ###################################
if (len(sys.argv) == 2):
list_of_files = os.listdir(sys.argv[1])
os.chdir(sys.argv[1])
else:
list_of_files = os.listdir(os.getcwd()) #getting the working directory's list of files
list_of_ext = ['.txt', '.pdf', '.jpg'] # add more!
###########functions bodies for the processing #################
#checking if the direrctory exists, if not then making it, then moving the file
# to the directory
def move_file(file_name,dir_name):
if (not os.path.exists(dir_name)):
os.mkdir(dir_name)
shutil.move(file_name, dir_name)
#checking the extension then returns the name of the directory so it will be as
# an arg to the #move_file function
def get_dir_name(ext):
if (ext == '.txt'):
return 'text_files'
elif (ext == '.pdf'):
return 'pdf_docs'
elif (ext == '.jpg'):
return 'jpg_images'
else:
return 0
#combining the two functions #move_file and #get_dir_name together
def check_and_move(file_list):
for file_name in file_list :
for ext in list_of_ext :
if (os.path.isfile(file_name)):
if (os.path.splitext(file_name)[1] == ext):
print "%s is a %s file" % (file_name, ext)
move_file(file_name, get_dir_name(ext))
###########checking and processing##################
check_and_move(list_of_files)
Last edited by Imadch (2017-01-25 01:25:15)
Offline
Welcome Imadch. That seems an odd way to organize files to me, but if it works for you, great. I suspect the code would be much cleaner and more efficient if you used an associative array of extensions -> directories. For each extension glob for all files of that type, then move those to the associated directory instead of getting *all* files and checking each on with string functions. As an added bonus, this associative array could be moved to a config file that is sourced so your code would be much easier to extend: just add a new entry to the array without having to rewrite the get_dir_name function.
I know all this is quite doable in python, but I'm crap at python, so here it is in bash:
#!/bin/bash
declare -A dir=(
[txt]="text_files"
[pdf]="pdf_docs"
[jpg]="jpg_images"
)
[[ -n $1 ]] && cd $1
for ext in "${!dir[@]}"; do
mkdir -p ${dir[$ext]}
mv *.$ext ${dir[$ext]}
done
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thank you so much for the replay and the advice , you made it so simple , i will use your script until i make mine works better
this is a simple try, i don't know if it will work i didn't try it
import os
import shutil
import sys
if (len(sys.argv) == 2):
if (os.path.exists(sys.argv[1])):
list_of_files = os.listdir(sys.argv[1])
os.chdir(sys.argv[1])
else:
list_of_files = os.listdir(os.getcwd())
dirs = {".txt":"text_files", ".pdf":"pdf_docs", ".jpg":"jpg_images" }
for file_name in list_of_files :
for ext, dir_name in dirs.items() :
os.mkdir(dir_name)
if (os.path.splitext(file_name)[1] == ext):
shutil.move(file_name, dir_name)
Offline
os.chdir is kind of dirty, you should usually prefer to use absolute paths in python.
You also have no error handling for the case where dir_name already exists, which is not unlikely (mkdir -p in the shell), and treat files as though they are directories (both of which are a regression from your original script).
An alternative which uses os.walk to recurse into subdirectories:
import os
import shutil
import sys
EXTENSION_DIRS = {".txt":"text_files", ".pdf":"pdf_docs", ".jpg":"jpg_images" }
# Discard extra args. We assume the shell has done expanduser for us.
if len(sys.argv) > 1 and os.path.isdir(sys.argv[1]):
workdir = sys.argv[1]
else:
workdir = '.'
for root, dirs, files in os.walk(workdir):
for file in files:
ext = os.path.splitext(file)[1]
if ext in EXTENSION_DIRS:
destdir = os.path.join(workdir, EXTENSION_DIRS.get(ext))
os.makedirs(destdir, exist_ok=True)
shutil.move(os.path.join(root, file), destdir)
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
This is bascially an open-url-with script. Newer version of lariza (at present in dev-external-handler branch) has feature to open url with external script, and the script is invoked with "lariza-external-handler -u $url". So I have created this script named lariza-external-handler. When invoked directly it opens url from clipboard, and when invoked by lariza it works with url forwarded by lariza.
#!/bin/bash
#which clipboard to use, valid options are "primary" and "clipboard"
SELECTION=clipboard
#choose your terminal
TERM=sakura
shopt -s lastpipe
ops=(
w3m
mpv
MPV
youtube-dl
YOUTUBE_DL
transmission
curl-download
curl-save
wget-saveall
add-bookmark
)
getopts u: name
case $name in
u) url=$OPTARG ;;
*) url="$(xclip -o -selection $SELECTION)" ;;
esac
[[ ! $url ]] && exit
# to use with rofi ##
option=$(for i in "${ops[@]}"; do echo "$i"; done | rofi -dmenu -location 1 -l 10 -width 100 -p : -font "Inconsolata 14" -mesg "open <u>$url</u> with...")
## uncomment below line to use with dmenu , and comment out line before this ##
# option=$(for i in "${ops[@]}"; do echo "$i"; done | /usr/bin/dmenu -b )
[[ ! $option ]] && exit
case "$option" in
w3m) $TERM -e w3m "$url" ;;
mpv) $TERM -e w3mpv "$url" ;;
MPV) $TERM -e mpv "$url" ;;
youtube-dl) $TERM -e w3ytdl "$url" ;;
YOUTUBE-DL) $TERM -e youtube-dl "$url" ;;
## download torrent using transmission-cli
transmission) $TERM -e transmission-remote-cli "$url" ;;
## downlod with curl in current dir (home)
curl-download) $TERM -e curl -L -O --user-agent Mozilla/5.0 "$url" ;;
## save page as curl.html in Downloads
curl-save) $TERM -e curl -L -o ~/Downloads/curl.html --user-agent Mozilla/5.0 "$url" ;;
## save full page with wget, saved in Downloads
wget-saveall) $TERM -e wget --user-agent=Mozilla/5.0 --mirror -p --convert-links -P ~/Downloads "$url" ;;
# add bookmark
add-bookmark)
echo -e "news\nlinux\ncycling\nsocial\nshopping\ntravel" | rofi -dmenu -location 1 -l 6 -width 100 -p : -font "Inconsolata 14" -mesg "choose tag for bookmark" | read tag
## uncomment below for use with dmenu and comment out the upper line ##
# echo -e "news\nlinux\ncycling\nsocial\nshopping\ntravel" | /usr/bin/dmenu -fn "Inconsolata 14" -p "choose tag" | read tag
echo "$url $tag" >> ~/.config/lariza/bookmarks ;;
## use any other external program chromium or firefox etc.
*) $option "$url" ;;
esac
note: w3mpv and w3ytdl are mpv and youtube-dl configured to choose smaller size (low resolution vids)
Arch is home!
https://github.com/Docbroke
Offline
os.chdir is kind of dirty, you should usually prefer to use absolute paths in python.
You also have no error handling for the case where dir_name already exists, which is not unlikely (mkdir -p in the shell), and treat files as though they are directories (both of which are a regression from your original script).An alternative which uses os.walk to recurse into subdirectories:
import os import shutil import sys EXTENSION_DIRS = {".txt":"text_files", ".pdf":"pdf_docs", ".jpg":"jpg_images" } # Discard extra args. We assume the shell has done expanduser for us. if len(sys.argv) > 1 and os.path.isdir(sys.argv[1]): workdir = sys.argv[1] else: workdir = '.' for root, dirs, files in os.walk(workdir): for file in files: ext = os.path.splitext(file)[1] if ext in EXTENSION_DIRS: destdir = os.path.join(workdir, EXTENSION_DIRS.get(ext)) os.makedirs(destdir, exist_ok=True) shutil.move(os.path.join(root, file), destdir)
thank you for the help , i couldn't find a way for sub directories before, now the script is more helpful for me :)
Offline
I know all this is quite doable in python, but I'm crap at python, so here it is in bash
Nice! You just taught me "declare" in bash.
Online
Trilby wrote:I know all this is quite doable in python, but I'm crap at python, so here it is in bash
Nice! You just taught me "declare" in bash.
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
Awebb wrote:Trilby wrote:I know all this is quite doable in python, but I'm crap at python, so here it is in bash
Nice! You just taught me "declare" in bash.
Woah! I'm speechless. How could I forget something so useful twice?
Online
scripts to mount and unmount a specific removable drive and bind it to specific folders this drive is inserted and removed regularly.
mount
#!/bin/sh
FILE="/dev/mapper/it"
if [ -e $FILE &> "/dev/null" ]; then
echo "already mounted";
exit 1
else
sudo cryptsetup --type luks open UUID=xxx it;
sudo mount -t filesystem /dev/mapper/it /mnt/it;
sudo mount --bind /here /here;
sudo mount --bind /here /here;
echo "succefully mounted"
exit 0
fi
umount
#!/bin/sh
FILE="/dev/mapper/it"
if pgrep process &> "/dev/null"; then
pkill proccess;(a specific thing that might be open but not background)
sudo umount "/here";
sudo umount "/here";
echo "successfully unmounted"
exit 0
elif [ -e $FILE &> "/dev/null" ]; then
sudo umount "/here";
sudo umount "/here";
echo "successfully unmounted"
exit 0
else
echo "not mounted";
exit 1
fi
edited some syntax
Last edited by bleach (2017-01-26 17:14:58)
Offline
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline