I have tried a few of the prompts that are available through the fish config tool. All of them have had prompts that become progressively shorter with a smaller window width. I personally don't like this as I always want to see the folder and git branch that I am in.
Is there a simple setting (or a popular off the shelf prompt) that makes the prompt be full width regardless of window width.
You can run the command fish_config, it will open a new tab in your browser, then select the Prompt tab and you will see some pre-setup prompts. If any of those suits you then you need to configure a prompt by yourself. On terminal you can do:
Go to .config/fish (generally it is located in your home folder. Linux or macOS you can do: cd ~/.config/fish
Create a folder named functions (mkdir functions ; cd functions)
Create a file named fish_prompt.fish with the content bellow:
function fish_prompt --description 'Informative prompt'
#Save the return status of the previous command
set -l last_pipestatus $pipestatus
switch "$USER"
case root toor
printf '%s#%s %s%s%s# ' $USER (prompt_hostname) (set -q fish_color_cwd_root
and set_color $fish_color_cwd_root
or set_color $fish_color_cwd) \
(prompt_pwd) (set_color normal)
case '*'
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color $fish_color_status) \
(set_color --bold $fish_color_status) $last_pipestatus)
printf '\f\r> %s%s#%s %s%s %s%s%s' (set_color brblue) \
$USER (prompt_hostname) (set_color $fish_color_cwd) $PWD \
(set_color normal)
end
end
Please, note that the code bellow is adapted from the Informative prompt
The Awesome Fish repository has some interesting prompts that you can install if you like.
Related
I would like to open a file and have nvim automatically be in search mode once the file is opened.
I need to find the correct command to use, probably in the form of nvim -c Command file.txt
To clarify, I want to start nvim and be able to start searching by typing in my search string without first pressing '/' to enter search mode.
running nvim -c '/searchString' executes the search immediately and is not what I want
My use case is that I use nvim as a scrollback pager for kitty.
# kitty passes text to nvim via stdinput which i write to a tmp file in /tmp/kitty_scrollback_buffer
# I then open this file with the nvim terminal by catting the file
# is there anyway to then automatically enter command search mode so that nvim is ready to search when i enter a search string (I do not want to type /, i want to be able to search immediately)
exec nvim \
-u NONE \
-c "silent! write! /tmp/kitty_scrollback_buffer | terminal cat /tmp/kitty_scrollback_buffer - " \
Yeah, you are right there. If you want to search foo in file.txt, run this:
nvim -c "/foo" file.txt
I have a folder full of jpg files which all end with "-x-large.jpg" I would like to rename them all using command line so that it gets rid of the -x-large and just becomes .jpg.
So for example 123-x-large.jpg will become 123.jpg
Can someone tell me how I can do this with the ren command?
Thanks.
for img in *-x-large.jpg; do mv -i -v "$img" "${img%-x-large.jpg}.jpg"; done
This loops on all matching images and moves them into a new file with a truncated name (removing -x-large.jpg from the end) with the .jpg added back to the end of the file name. I'm invoking this interactively with mv -i so you are prompted before overwriting each file. To force overwriting (always say "yes"), change that to mv (remove the -i). To prevent overwriting (always say "no"), change that to mv -n.
Remove the -v (verbose) if you don't want to see each rename happen.
If you have a very large number of these files, the command line will be too long for the above command (since *-x-large.jpg will be expanded onto a command line). You can work around that with find and xargs as follows:
sh <(find . -maxdepth 1 -name '*-x-large.jpg' \
|sed -r 's/(.*)(-x-large.jpg)$/mv -i "\1\2" "\1.jpg"/')
This creates a shell script using bash process substitution, using find to generate a list of all files we want to rename and then piping them through sed to create the mv commands.
(See above for the mv flags. I removed -v because presumably this will be a very long list.)
See the version below if you want to check the script before running it.
The above one-liner requires GNU bash or Korn shell (ksh) as well as GNU sed.
Here's how to do it with neither (in three commands):
find . -maxdepth 1 -name '*-x-large.jpg' \
|sed 's/.*/mv "&" "&/; s/-x-large.jpg$/.jpg"/' > temp.sh
sh temp.sh
rm temp.sh
Posix sed doesn't reliably support capture groups (\(…\) or sed -r to invoke ERE) and therefore we can't expect it to be able to match and recall text, so this version simply writes most of the command and then fixes the ending (the absence of a trailing double quotes in the first replacement is intentional; we add it in the second replacement). Posix shell (/bin/sh proper) doesn't support process substitution, so we dump to a temporary file, evaluate it, and then remove it.
If we're referring to Windows command-line, then SET /? is your friend. Loads of good info in there.
setlocal ENABLEDELAYEDEXPANSION
set SEARCH_SUFFIX=-x-large.jpg
set REPLACE_SUFFIX=.jpg
for %%A in ("*%SEARCH_SUFFIX%") do (
set OLD_NAME=%%~nxA
set NEW_NAME=!OLD_NAME:%SEARCH_SUFFIX%=%REPLACE_SUFFIX%!
ren "!OLD_NAME!" "!NEW_NAME!"
)
endlocal
I'm trying to automate disabling the Transparent Huge Pages (THP) Settings for MongoDB using a Chef Recipe.
The THP setting is explained here: MongoDocs THP Settings
I'm trying to follow the first option "In Boot-Time Configuration (Preferred)" by editing the grub configuration file at "/etc/grub.conf"
All I need to do is append "transparent_hugepage=never" to the end of the existing line that starts with "kernel "
I know I can replace a line with Chef::Util::FileEdit, using something like this:
ruby_block "replace_line" do
block do
file = Chef::Util::FileEdit.new("/etc/grub.conf")
file.search_file_replace_line("/kernel/", "kernel <kernel path> <kernel options> transparent_hugepage=never")
file.write_file
end
end
but I need to keep the existing kernel path and kernel options.
I've tried playing around with Chef::Util::Editor, but haven't been successful initializing the constructor. Chef::Util::FileEdit is initialized with a file path (per above), but the ruby docs say that Chef::Util::Editor is initialized with "lines". I've tried
lines = Chef::Util::Editor.new(<lines>)
where <lines> = file path, = Chef::Util::FileEdit.new(), and = 'test string', but nothing seems to work.
Does anyone have any experience with the Chef::Util::Editor? Or a better solution?
Thanks
I never figured out how to modify a single line in a config file using Chef, but here's the recipe I ended up using to disable THP settings for MongoDB.
Recipe: Install MongoDB
# Install MongoDB on Amazon Linux
# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-amazon/
# 1: configure the package management system (yum)
# 2: install mongodb
# 3: configure mongodb settings
# 3.A: give mongod permission to files
# data & log directories (everything in /srv/mongodb)
# http://stackoverflow.com/questions/7948789/mongodb-mongod-complains-that-there-is-no-data-db-folder
execute "mongod_permission" do
command "sudo chown -R mongod:mongod /srv/mongodb"
#command "sudo chown mongod:mongod /var/run/mongodb/mongod.pid"
#command "sudo chown -R $USER /srv/mongodb"
end
# 3.B: edit Transparent Huge Pages (THP) Settings
# get rid of mongod startup warning
# http://docs.mongodb.org/manual/reference/transparent-huge-pages/#transparent-huge-pages-thp-settings
# 3.B.1: disable
execute "disable_thp_khugepaged_defrag" do
command "echo 0 | sudo tee /sys/kernel/mm/transparent_hugepage/khugepaged/defrag" # different b/c file doesn't have options list
end
execute "disable_thp_hugepage_defrag" do
command "echo 'never > /sys/kernel/mm/transparent_hugepage/defrag' | sudo tee --append /sys/kernel/mm/transparent_hugepage/defrag"
end
execute "disable_thp_hugepage_enables" do
command "echo 'never > /sys/kernel/mm/transparent_hugepage/enabled' | sudo tee --append /sys/kernel/mm/transparent_hugepage/enabled"
end
# 3.B.2: verify disabled on reboot
template "/etc/rc.local" do
source "init-rc.local.erb"
owner 'root'
group 'root'
mode '0775'
end
# 4: use upstart & monit to keep mongod alive
Template: init-rc.local.erb
touch /var/lock/subsys/local
if test -f /sys/kernel/mm/transparent_hugepage/khugepaged/defrag; then
echo 0 > /sys/kernel/mm/transparent_hugepage/khugepaged/defrag
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
The problem with your own solution is the template can be overwritten by another recipe with it's own rc.local template.
To change that, I add the lines to the existing rc.local
execute "disable_thp_hugepage_defrag" do
command "sudo sed -i -e '$i \\echo never > /sys/kernel/mm/transparent_hugepage/defrag\\n' /etc/rc.local"
not_if 'grep -c "transparent_hugepage/defrag" /etc/rc.local'
end
execute "disable_thp_hugepage_enables" do
command "sudo sed -i -e '$i \\echo never > /sys/kernel/mm/transparent_hugepage/enabled\\n' /etc/rc.local"
not_if 'grep -c "transparent_hugepage/enabled" /etc/rc.local'
end
The grep makes sure that the line is not already in it.
Maybe chef has something better to manage that?
We can efficietly replace contents of file by grouping the elements
e.g.
appending "transparent_hugepage=never" to the end of the existing line that starts with "kernel "
ruby_block "replace_line" do
block do
file = Chef::Util::FileEdit.new("/etc/grub.conf")
file.search_file_replace_line(/kernel.*/, '\0 tansparent_hugepage=never')
file.write_file
end
end
\0 adds whole mached string
note: ' '(single quote)
I disabled hugepages by replicating the following in chef (looks the same as above but with the addition of a not_if statement):
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/defrag
E.G
execute "disable_hugepage_defrag" do
not_if "grep -F '[never]' /sys/kernel/mm/transparent_hugepage/defrag"
command "echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag"
end
I have also had success inserting lines with file.insert_line_if_no_match the ruby line replace feature will probably work for you.
search_file_replace_line(regex, newline) ⇒ Object
ruby_block 'replace_line' do
block do
file = Chef::Util::FileEdit.new('/path/to/file')
file.search_file_replace_line('/Line to find/', 'Line to replace with')
file.write_file
end
end
I am trying to interface between tk and cshell-script.
I am able to collect data using tk:
label .firstColumn.s.variable.label -text "myFirstVariable" -background $color3
entry .firstColumn.s.variable.entry -textvariable program
But when I try to run the command it does not work
button .secondColumn.o.buttons.go -text "Run Now" \
-command "exec sed -i {s/ABC/$myFirstVariable/g} runme.sh \
>! runmeNow.sh ; ./runmeNow"
It changes ABC to blank in runmeNow.sh file.
Is there any better way to achieve it?
I want to replace a place-holder predefined in cshell-script (runme.sh). My place holder is ABC. Then I want to pipe it to a different file, then run this file. runme.sh has UNIX based run file.
Seems to me that tk is interpreting $myFirstVariable as a variable of its own, while you'd like it to be forwarded to shell. Escaping the dollar sign with a backslash may not be enough: exec is a Tcl command and doesn't use a shell, so we may have to call one to expand shell variable:
button .secondColumn.o.buttons.go -text "Run Now" \
-command "exec /bin/sh -i {sed "s/ABC/$myFirstVariable/g" runme.sh \
> runmeNow.sh ; ./runmeNow.sh}"
I'm trying to find a script to find and move files to a different folder.
I've got a folder with hundreds pictures like this:
PA-600-01.jpg, PA-600-02.jpg, PA-600-03.jpg, PA-600-04.jpg, PA-601-01.jpg, PA-601-02.jpg, PA-601-03.jpg, PA-602-01.jpg, PA-602-02.jpg, PA-602-03.jpg, PA-602-04.jpg, PA-602-05.jpg
I want to move all the pictures with PA-600 (so PA-600-01.jpg, PA-600-02.jpg, PA-600-03.jpg and PA-600-04.jpg) on a folder (new or already existing, the easier...) named PA-600, move all the pictures with PA-601 (PA-601-01.jpg, PA-601-02.jpg and PA-601-03.jpg) on a folder named PA-601, move all the pictures with PA-602 (PA-602-01.jpg, PA-602-02.jpg, PA-602-03.jpg, PA-602-04.jpg and PA-602-05.jpg) on a folder named PA-602... until PA-699
I tried to move a file but not a group of files:
tell application "Finder" make new folder at alias "Macintosh HD:Users:AirYoSo:Desktop:600-699" with properties {name:"PA-600"} copy file "Macintosh HD:Users:AirYoSo:Desktop:600-699:PA-600-01.jpg" to folder "Macintosh HD:Users:AirYoSo:Desktop:600-699:PA-600" end tell
Try:
set myFolder to (choose folder)
set pFolder to POSIX path of myFolder
set folderNames to paragraphs of (do shell script "find " & quoted form of pFolder & " \\! -name \".*\" -type f -print0 | xargs -0 ls -t | grep -Eo PA-[0-9]{3} | uniq")
repeat with aFolder in folderNames
(do shell script "mkdir -p " & quoted form of (pFolder & aFolder))
tell application "System Events" to move (every file of myFolder whose name begins with aFolder) to (pFolder & aFolder)
end repeat
EDIT
If you want to hard wire the path to the folder you can use:
set myFolder to "Macintosh HD:Users:YoSo:Desktop:test"
set pFolder to myFolder's POSIX path & "/"
set folderNames to paragraphs of (do shell script "find " & quoted form of pFolder & " \\! -name \".*\" -type f -print0 | xargs -0 ls -t | grep -Eo PA-[0-9]{3} | uniq")
repeat with aFolder in folderNames
(do shell script "mkdir -p " & quoted form of (pFolder & aFolder))
tell application "System Events" to move (every file of folder myFolder whose name begins with aFolder) to (pFolder & aFolder)
end repeat
No idea how to do it in applescript, but this is quite trivial to do in bash, which you have installed on your Mac:
#!/bin/bash
for (( c=600; c<=699; c++ ))
do
echo "Processing PA-$c"
mkdir -p PA-$c
mv PA-$c-*.jpg PA-$c/
done
Save this to a file, for example script.sh, copy the file to the directory with your jpg files, and run it like this, in Terminal (replace /Users/lionel/files with the real path to your files):
$ cd /Users/lionel/files
$ bash script.sh